Laravel 4.2 — Sentry — Не возвращается правильный вид

Я разрабатываю приложение CRUD с Laravel 4.2 и использую Sentry 2 для регистрации и группировки пользователей. Я создал модель для животных и AnimalController, чтобы администратор мог видеть / редактировать и удалять животных из БД. Я создал все виды, такие как: views / animales / create.blade.php. Однако, когда я пытаюсь вызвать представление animales / create для отображения формы для ввода нового животного, я получаю исключение ошибки:

«Попытка получить свойство не-объекта (View: … / app / views / animales / show.blade.php)»

Что на самом деле не тот взгляд, который я называю. Вот мои маршруты:

Route::group(['before' => 'auth|admin'], function()
{
Route::resource('animales', 'AnimalController');
}

и вот мой диспетчер животных:

 class AnimalController extends \BaseController {

/**
* Display a listing of the resource.
*
* @return Response
*/
public function index()
{
// get all the animals & ganaderias
$animals = DB::table('animals')->where('categoria', 'Listado')->get();

$ganaderias = Ganaderia::lists('nombre', 'id');// load the view and pass the animals
return View::make('animales.index', array('animals' => $animals, 'ganaderias' => $ganaderias ));
}/**
* Show the form for creating a new resource.
*
* @return Response
*/
public function create()
{
//get all the ganaderias nombres & ids into an array to bind to form select
$ganaderias = Ganaderia::lists('nombre', 'id');

// load the create form (app/views/animales/create.blade.php)
return View::make('animales.create', array('ganaderias' => $ganaderias));
}/**
* Store a newly created resource in storage.
*
* @return Response
*/
public function store()
{
// store new animal in db
$input = Input::all();

Animal::create([
'sexo' => $input['sexo'],
'registro' => $input['registro'],
'dib' => $input['dib'],
'fecha_de_nacimiento' => $input['fecha_de_nacimiento'],
'fecha_de_calificacion' => $input['fecha_de_calificacion'],
'calificacion' => $input['calificacion'],
'padre' => $input['padre'],
'madre' => $input['madre'],
'adn' => $input['adn'],
'fecha_de_transaccion' => $input['fecha_de_transaccion'],
'observaciones' => $input['observaciones'],
'fecha_de_baja' => $input['fecha_de_baja'],
'causa_de_baja' => $input['causa_de_baja'],
'citogenetica' => $input['citogenetica'],
'ganaderia_id' => $input['ganaderia_id'],
'categoria' => $input['categoria']]);
return Redirect::to('animales');
}/**
* Display the specified resource.
*
* @param  int  $id
* @return Response
*/
public function show($id)
{
$animal = Animal::find($id);

$ganaderia = Ganaderia::where( 'id', '=', 'ganaderia_id')->get();

// show the view and pass the nerd to it
return View::make('animales.show', array('animal' => $animal, 'ganaderia' => $ganaderia ));
}/**
* Show the form for editing the specified resource.
*
* @param  int  $id
* @return Response
*/
public function edit($id)
{
// get the animal
$animal = Animal::find($id);

//get all the ganaderias nombres & ids into an array to bind to form select
$ganaderias = Ganaderia::lists('nombre', 'id');

// show the view and pass the nerd to it
return View::make('animales.edit', array('animal' => $animal, 'ganaderia' => $ganaderias ));
}/**
* Update the specified resource in storage.
*
* @param  int  $id
* @return Response
*/
public function update($id)
{
// validate
// read more on validation at http://laravel.com/docs/validation
$rules = array(
'sexo'       => 'required',
'fecha_de_calificacion'      => 'required',
'calificacion' => 'required',
'dib' => 'required',
'registro' => 'required',
'padre' => 'required',
'madre' => 'required',
);
$validator = Validator::make(Input::all(), $rules);

// process the login
if ($validator->fails()) {
return Redirect::to('animales/' . $id . '/edit')
->withErrors($validator)
->withInput();
} else {
// store
$animal = Animal::find($id);
$animal->sexo       = Input::get('sexo');
$animal->registro       = Input::get('registro');
$animal->dib      = Input::get('dib');
$animal->fecha_de_nacimiento = Input::get('fecha_de_nacimiento');
$animal->fecha_de_muerte       = Input::get('fecha_de_muerte');
$animal->fecha_de_calificacion       = Input::get('fecha_de_calificacion');
$animal->calificacion       = Input::get('calificacion');
$animal->fecha_de_baja       = Input::get('fecha_de_baja');
$animal->causa_de_baja       = Input::get('causa_de_baja');
$animal->fecha_de_transaccion       = Input::get('fecha_de_transaccion');
$animal->padre       = Input::get('padre');
$animal->madre       = Input::get('madre');
$animal->observaciones       = Input::get('observaciones');
$animal->citogenetica       = Input::get('citogenetica');
$animal->adn       = Input::get('adn');
$animal->partos       = Input::get('partos');
$animal->partos_no_lg       = Input::get('partos_no_lg');
$animal->ganaderia_id       = Input::get('ganaderia_id');
$animal->categoria          = Input::get('categoria');
$animal->save();

// redirect
Session::flash('message', 'Animal editado correctamente!');
return Redirect::to('animales');
}
}/**
* Remove the specified resource from storage.
*
* @param  int  $id
* @return Response
*/
public function destroy($id)
{
// delete
$animal = Animal::find($id);
$animal->delete();

// redirect
Session::flash('message', 'Este animal fue eliminado correctamente!');
return Redirect::to('animales');
}}/**
* Show the form for editing the specified resource.
*
* @param  int  $id
* @return Response
*/
public function edit($id)
{
// get the animal
$animal = Animal::find($id);

//get all the ganaderias nombres & ids into an array to bind to form select
$ganaderias = Ganaderia::lists('nombre', 'id');

// show the view and pass the nerd to it
return View::make('animales.edit', compact('animal', 'ganaderias'));
}/**
* Update the specified resource in storage.
*
* @param  int  $id
* @return Response
*/
public function update($id)
{
// validate
// read more on validation at http://laravel.com/docs/validation
$rules = array(
'sexo'       => 'required',
'fecha_de_calificacion'      => 'required',
'calificacion' => 'required',
'dib' => 'required',
'registro' => 'required',
'padre' => 'required',
'madre' => 'required',
);
$validator = Validator::make(Input::all(), $rules);

// process the login
if ($validator->fails()) {
return Redirect::to('animales/' . $id . '/edit')
->withErrors($validator)
->withInput();
} else {
// store
$animal = Animal::find($id);
$animal->sexo       = Input::get('sexo');
$animal->registro       = Input::get('registro');
$animal->dib      = Input::get('dib');
$animal->fecha_de_nacimiento = Input::get('fecha_de_nacimiento');
$animal->fecha_de_muerte       = Input::get('fecha_de_muerte');
$animal->fecha_de_calificacion       = Input::get('fecha_de_calificacion');
$animal->calificacion       = Input::get('calificacion');
$animal->fecha_de_baja       = Input::get('fecha_de_baja');
$animal->causa_de_baja       = Input::get('causa_de_baja');
$animal->fecha_de_transaccion       = Input::get('fecha_de_transaccion');
$animal->padre       = Input::get('padre');
$animal->madre       = Input::get('madre');
$animal->observaciones       = Input::get('observaciones');
$animal->citogenetica       = Input::get('citogenetica');
$animal->adn       = Input::get('adn');
$animal->partos       = Input::get('partos');
$animal->partos_no_lg       = Input::get('partos_no_lg');
$animal->ganaderia_id       = Input::get('ganaderia_id');
$animal->categoria          = Input::get('categoria');
$animal->save();

// redirect
Session::flash('message', 'Animal editado correctamente!');
return Redirect::to('animales');
}
}/**
* Remove the specified resource from storage.
*
* @param  int  $id
* @return Response
*/
public function destroy($id)
{
// delete
$animal = Animal::find($id);
$animal->delete();

// redirect
Session::flash('message', 'Este animal fue eliminado correctamente!');
return Redirect::to('animales');
}}

Вот файл фильтра:

                    /*
|--------------------------------------------------------------------------
| Application & Route Filters
|--------------------------------------------------------------------------
|
| Below you will find the "before" and "after" events for the application
| which may be used to do any work before or after a request into your
| application. Here you may also register your custom route filters.
|
*/

App::before(function($request)
{
//
});App::after(function($request, $response)
{
//
});

/*
|--------------------------------------------------------------------------
| Authentication Filters
|--------------------------------------------------------------------------
|
| The following filters are used to verify that the user of the current
| session is logged into this application. The "basic" filter easily
| integrates HTTP Basic authentication for quick, simple checking.
|
*/

Route::filter('auth', function()
{
if (!Sentry::check()) return Redirect::guest('login');
});

// Route::filter('auth', function()
// {
//  if (Auth::guest()) return Redirect::guest('login');
// });

Route::filter('admin', function()
{
$user = Sentry::getUser();
$admin = Sentry::findGroupByName('Admins');

if (!$user->inGroup($admin))
{
return Redirect::to('login');
}
});Route::filter('standardUser', function()
{
$user = Sentry::getUser();
$users = Sentry::findGroupByName('Users');

if (!$user->inGroup($users))
{
return Redirect::to('login');
}
});Route::filter('auth.basic', function()
{
return Auth::basic();
});

/*
|--------------------------------------------------------------------------
| Guest Filter
|--------------------------------------------------------------------------
|
| The "guest" filter is the counterpart of the authentication filters as
| it simply checks that the current user is not logged in. A redirect
| response will be issued if they are, which you may freely change.
|
*/

Route::filter('guest', function()
{
if (Sentry::check())
{
// Logged in successfully - redirect based on type of user
$user = Sentry::getUser();
$admin = Sentry::findGroupByName('Admins');
$users = Sentry::findGroupByName('Users');

if ($user->inGroup($admin)) return Redirect::intended('admin');
elseif ($user->inGroup($users)) return Redirect::intended('/');
}
});

// Route::filter('guest', function()
// {
//  if (Auth::check()) return Redirect::to('/');
// });

Route::filter('redirectAdmin', function()
{
if (Sentry::check())
{
$user = Sentry::getUser();
$admin = Sentry::findGroupByName('Admins');

if ($user->inGroup($admin)) return Redirect::intended('admin');
}
});Route::filter('currentUser', function($route)
{

if (!Sentry::check()) return Redirect::home();

if (Sentry::getUser()->id != $route->parameter('profiles'))
{
return Redirect::home();
}
});

/*
|--------------------------------------------------------------------------
| CSRF Protection Filter
|--------------------------------------------------------------------------
|
| The CSRF filter is responsible for protecting your application against
| cross-site request forgery attacks. If this special token in a user
| session does not match the one given in this request, we'll bail.
|
*/

Route::filter('csrf', function()
{
if (Session::token() != Input::get('_token'))
{
throw new Illuminate\Session\TokenMismatchException;
}
});

А вот и мой show.blade.php:

<!DOCTYPE html>
<html>
<head>
<title>Muestra un animal</title>
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css">
</head>
<body>
<div class="container">

@include('../partials/navigation')

<h1>Mostrando vaca con el DIB: {{ $animal->dib }}</h1>

<div class="jumbotron">

<p>
<strong>Sexo:</strong> {{ $animal->sexo }}<br>
<strong>Registro:</strong> {{ $animal->registro }}<br>
<strong>DIB:</strong> {{ $animal->dib }}<br>
<strong>Fecha de nacimiento:</strong> {{ $animal->fecha_de_nacimiento }}<br>
<strong>Fecha de muerte:</strong> {{ $animal->fecha_de_muerte }}<br>
<strong>Calificación:</strong> {{ $animal->calificacion }}<br>
<strong>Fecha de calificación:</strong> {{ $animal->fecha_de_calificacion }}<br>
<strong>Fecha de baja:</strong> {{ $animal->fecha_de_baja }}<br>
<strong>Causa de la baja:</strong> {{ $animal->causa_de_baja }}<br>
<strong>Fecha de transacción:</strong> {{ $animal->fecha_de_transaccion }}<br>
<strong>Padre:</strong> {{ $animal->padre }}<br>
<strong>Madre:</strong> {{ $animal->madre }}<br>
<strong>Observaciones:</strong> {{ $animal->observaciones }}<br>
<strong>Citogenética:</strong> {{ $animal->citogenetica }}<br>
<strong>Fecha de la baja:</strong> {{ $animal->fecha_de_baja }}<br>
<strong>Causa de la baja:</strong> {{ $animal->causa_de_baja }}<br>
<strong>ADN:</strong> {{ $animal->adn }}<br>
<strong>Citogenética:</strong> {{ $animal->citogenetica }}<br>
<strong>Partos:</strong> {{ $animal->partos }}<br>
<strong>Partos no LG:</strong> {{ $animal->partos_no_lg }}<br>
<strong>Ganadería:</strong> {{ $animal->ganaderia->nombre }}</p>
</div>
@include('../partials/footer')
</div>
</body>
</html>

Вот мой вид создания:

<!DOCTYPE html>
<html>
<head>
<title>Registrar un animal</title>
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css">
</head>
<body>
<div class="container">

@include('../partials/navigation')

<!-- will be used to show any messages -->
@if (Session::has('message'))
<div class="alert alert-info">{{ Session::get('message') }}</div>
@endif

<h1>Registrar un animal</h1>

@if ($errors->has())
<div class="alert alert-danger">
@foreach ($errors->all() as $error)
{{ $error }}<br>
@endforeach
</div>
@endif

<!-- FORM STARTS HERE -->
{{ Form::open(['url' => '/animales/create'])}}
<div>
{{ Form::label('sexo', 'Sexo:')}}
{{ Form::select('sexo', array('M'=>'macho', 'H'=> 'hembra', 'C' => 'castrado'))}}
</div>
<div>
{{ Form::label('registro', 'Registro:')}}
{{ Form::select('registro', array('F'=>'fundacional', 'N'=> 'nacimientos', 'D' => 'definitivo','A' => 'registro auxiliar A', 'B' => 'registro auxiliar B'))}}
</div>
<div>
{{ Form::label('dib', 'DIB:')}}
{{ Form::input('number', 'dib')}}
</div>
<div>
{{ Form::label('fecha_de_nacimiento', 'Fecha de nacimiento:')}}
{{ Form::input('date', 'fecha_de_nacimiento')}}
</div>

<div>
{{ Form::label('fecha_de_calificacion', 'Fecha de calificacion:')}}
{{ Form::input('date', 'fecha_de_calificacion')}}
</div>
<div>
{{ Form::label('calificacion', 'Calificacion:')}}
{{ Form::input('number', 'calificacion')}}
</div>
<div>
{{ Form::label('padre', 'Padre:')}}
{{ Form::text('padre')}}
</div>
<div>
{{ Form::label('madre', 'Madre:')}}
{{ Form::text('madre')}}
</div>
<div>
{{ Form::label('adn', 'ADN:')}}
{{ Form::text('adn')}}
</div>
<div>
{{ Form::label('fecha_de_transaccion', 'Fecha de transacción:')}}
{{ Form::input('date', 'fecha_de_transaccion')}}
</div>
<div>
{{ Form::label('observaciones', 'Observaciones:')}}
{{ Form::textarea('observaciones')}}
</div>
<div>
{{ Form::label('fecha_de_baja', 'Fecha de la baja:')}}
{{ Form::input('date', 'fecha_de_baja')}}
</div>
<div>
{{ Form::label('causa_de_baja', 'Causa de la baja:')}}
{{ Form::select('causa_de_baja', array('' => '', 'V'=>'Venta (vida)', 'M'=> 'Muerte', 'S' => 'Sacrificio', 'D' => 'Descalificado', 'N' => 'No asociación'))}}
</div>
<div>
{{ Form::label('partos_no_lg', 'Partos no LG:')}}
{{ Form::input('date', 'partos_no_lg')}}
</div>
<div>
{{ Form::label('partos', 'Partos:')}}
{{ Form::input('number', 'partos')}}
</div>
<div>
{{ Form::label('citogenetica', 'Citogenética:')}}
{{ Form::select('citogenetica', array('' => '', 'L'=>'libre', 'HE'=> 'heterocigoto', 'HO' => 'homocigoto'))}}
</div>
<div>
{{ Form::label('ganaderia_id', 'Ganaderia:')}}
{{ Form::select('ganaderia_id', $ganaderias)}}
</div>
<div>
{{ Form::label('categoria', 'Categoría:')}}
{{ Form::select('categoria', array('Listado'=>'En lista', 'Archivado'=> 'Archivado'))}}
</div>
<div>
{{ Form::submit('Registrar animal')}}

</div>

{{ Form::close()}}

@include('../partials/footer')

</div>
</body>
</html>

Кто-нибудь может помочь? Спасибо!

0

Решение

Попробуй это:

public function show($id)
{
$animal = Animal::find($id);

$ganaderia = Ganaderia::where( 'id', '=', 'ganaderia_id')->get();

// show the view and pass the nerd to it
return View::make('animales.show', array('animal' => $animal, 'ganaderia' => $ganaderia ));
}
0

Другие решения

Так я звонил по тому же маршруту (Route::resource('animales', 'AnimalController');) в другой группе маршрутов. Как только я удалил маршрут из этой другой группы, все заработало. В любом случае, большое спасибо за помощь!

0

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector