Error in updating the input field,Laravel - php

So I have this edit form it contains a field for the building name and an image.
The problem is when I try to edit and click update the building name it show this error:
Call to a member function getClientOriginalExtension() on null
But when I change the image and click update its working as long as you don't change the building name.
Here is the code:
editbuilding.blade.php
{!! Form::open(array('route' => ['editbuilding',$id], 'class' => 'form' , 'files'=>'true')) !!}
<div class="container">
<div class="form-group">
{!! Form::label('Building Name') !!}
{!! Form::text('buildingname', $building->name, array('required',
'class'=>'form-control',
'placeholder'=>'Building Name')) !!}
</div>
<div class="form-group">
{!! Form::label('Building Name') !!}
{!! Form::file('buildingpics',
array('onchange'=>'previewFile()')) !!}
#if ($building->picture)
<br/><img src="{{asset('assets/'.$building->picture)}}" id="previewImg" style="height:300px; width:300px;" alt="">
#else
</br><p>No image found</p>
#endif
</div>
<div class="form-group">
{!! Form::submit('Update',
array('class'=>'btn btn-primary')) !!}
Back
</div>
</div>
{!! Form::close() !!}
<script type="text/javascript">
function previewFile() {
var preview = document.querySelector('#previewImg');
var file = document.querySelector('input[type=file]').files[0];
var reader = new FileReader();
reader.addEventListener("load", function () {
preview.src = reader.result;
}, false);
if (file) {
reader.readAsDataURL(file);
}
}
</script>
#endsection
#section('scripts')
#endsection
BuildingController.php
public function saveBuilding(Request $request)
{
$file = $request->file('buildingpics');
$building = new Building();
$building->name = $request->buildingname;
$building->picture = $building->name.'.'.$file->getClientOriginalExtension();
$file->move('assets',$building->name.'.'.$file->getClientOriginalExtension());
$building->save();
\Session::flash('building_flash', 'Created successfully!');
return redirect('/');
}
public function edit($id)
{
$building = Building::find($id);
return view('editbuilding')->withBuilding($building)->with('id',$id);
}
/**
* Update the specified resource in storage.
*
* #param \Illuminate\Http\Request $request
* #param int $id
* #return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
$building = Building::find($id);
$building->name = $request->buildingname;
$file = $request->file('buildingpics');
$building->picture = $building->name.'.'.$file->getClientOriginalExtension();
// print_r(FCPATH);
// dd($file);
$file->move('assets',$building->name.'.'.$file->getClientOriginalExtension());
$building->update();
\Session::flash('building_flash', 'Updated successfully!');
return redirect()->back();
}

You have to add test if there is an uploaded file or not :
public function update(Request $request, $id)
{
$building = Building::find($id);
$building->name = $request->buildingname;
$file = $request->file('buildingpics');
if($file != null) {
$building->picture = $building->name.'.'.$file->getClientOriginalExtension();
// print_r(FCPATH);
// dd($file);
$file->move('assets',$building->name.'.'.$file->getClientOriginalExtension());
}
$building->update();
\Session::flash('building_flash', 'Updated successfully!');
return redirect()->back();
}

You should check it first if there is any file posted by the request. You can check it with function:
$request->hasFile('buildingpics');
So your code should be look like:
public function update(Request $request, $id)
{
...
if ($request->hasFile('buildingpics'))
// do saving file and set picture field here
}
...
}

Related

How to display the last inserted id in db using Laravel after creating

Patient Controller:
public function store(Request $request)
{
$input = request()->all();
Patient::create($input);
dd($input->id);
// return redirect()->route('medical.create',compact('input'));
}
This is my medical.create view
{!! Form::model($input, [
'method' => 'POST',
'action' => ['MedicalController#store', $input->id]
]) !!}
<div class="row">
<div class="col-md-4">
<div class="form-group">
{{Form::label('patient_id','Patient no:')}}
{{Form::text('patient_id', null, array('class' => 'form-control') )}}
</div>
</div>
</div>
{!! Form::close() !!}
I want to get my last inserted id after storing, and display the last id in the next form, but this is the error appear in my screen:
Trying to get property 'id' of non-object
This is my Patient table:
You can do that by saving the Patient object in a variable when creating it:
public function store(Request $request)
{
$input = request()->all();
$patient = Patient::create($input); // Save it in variable
dd($patient->id); //Now you can access patient id here
// return redirect()->route('medical.create',compact('patient')); //Also you can pass it to your view
}
you can use id like Code below with least Changes in your code
$input = request()->all();
$input = Patient::create($input);
dd($input->id);
// return redirect()->route('medical.create',compact('input'));
you can retrive id after saving data by mass assignments :
public function store(Request $request)
{
$input = request()->all();
$patient = new Patient($input); // fill model with mass assignments
$patient->save() // save instant
$id = $patient->id; //retrive id
}
You can't use compact while redirecting. Try this:
Patient Controller:
public function store(Request $request)
{
$input = request()->all();
$patient = Patient::create($input);
$patient = DB::table('patients')->get()->last();
return redirect()->route('medical.create')->with('patient_id', $patient->id);
}
This is my medical.create view
{!! Form::model($input, [
'method' => 'POST',
'action' => ['MedicalController#store', session('patient_id')]
]) !!}
<div class="row">
<div class="col-md-4">
<div class="form-group">
{{Form::label('patient_id','Patient no:')}}
{{Form::text('patient_id', null, array('class' => 'form-control') )}}
</div>
</div>
</div>
{!! Form::close() !!}

How to pass $id of a form to another form

I have multiple forms where I need to pass through the id. In the example bellow I have 2 controllers one is for Courses and one is for the Exams. I'm trying to create a course and then pass through the course id to the exam form.
Here is what I've tried but the value is not passing through.
Course Controller:
public function store(StoreCoursesRequest $request)
{
if (! Gate::allows('course_create')) {
return abort(401);
}
$request = $this->saveFiles($request);
$course = Course::create($request->all()
// $status = array('assigned' => 'assigned', 'canceled'=>'canceled');
+ ['position' => Course::where('curriculum_id', $request->curriculum_id)->max('position') + 1]);
$trainers = \Auth::user()->isAdmin() ? array_filter((array)$request->input('trainers')) : [\Auth::user()->id];
$course->trainers()->sync($trainers);
$course->roles()->sync(array_filter((array)$request->input('roles')));
$course->assigned_user()->sync(array_filter((array)$request->input('assigned_user')));
$curriculum = Curriculum::get(array('id' => 'id'));
$exam = Exam::get(array('id' => 'id'));
foreach ($request->input('course_materials_id', []) as $index => $id) {
$model = config('medialibrary.media_model');
$file = $model::find($id);
$file->model_id = $course->id;
$file->save();
}
session('id', 'id');
return redirect()->route('admin.exams.create');
}
Here is the exams controller
public function create()
{
if (! Gate::allows('exam_create')) {
return abort(401);
}
$exam_assigneds = \App\Exam::get()->pluck('title', 'id')->prepend(trans('global.app_please_select'), '');
$questions = \App\ExamQuestion::get()->pluck('question', 'id');
$in_classes = \App\InClassCourse::get()->pluck('title', 'id')->prepend(trans('global.app_please_select'), '');
$reoccurance_type = \App\ReoccuranceType::get()->pluck('type', 'id')->prepend(trans('global.app_please_select'), '');
$courses = session('id');
return view('admin.exams.create', compact('courses', 'exam_assigneds', 'questions', 'in_classes', 'reoccurance_type'));
}
Here is the view
<div class="row">
<div class="col-xs-12 form-group">
{!! Form::label('course_id', trans('global.exam.fields.course').'', ['class' => 'control-label']) !!}
{!! Form::text('id', $courses, old('id'), ['class' => 'form-control', 'placeholder' => '']) !!}
<p class="help-block"></p>
#if($errors->has('course_id'))
<p class="help-block">
{{ $errors->first('course_id') }}
</p>
#endif
</div>
</div>
All I'm getting is just text value of id. It doesn't pull the actual id.
In Course Controller modify
session('id', 'id');
to
session('id', $course->id);

Laravel update makes new table rule instead of updating

I have a company table and an attributes table with all sorts of value in it.
One company hasMany attributes and an attribute belongsTo a company.
Now I have a value inside the attributes table with a 'account_nr_start' (for example, when a new user is added to a company its account_id starts counting up from 1000).
Controller:
public function __construct(Company $company, User $user)
{
if(Auth::user()->usertype_id == 7)
{
$this->company = $company;
}
else
{
$this->company_id = Auth::user()->company_id;
$this->company = $company->Where(function($query)
{
$query->where('id', '=', $this->company_id )
->orWhere('parent_id','=', $this->company_id);
}) ;
}
$this->user = $user;
$this->middleware('auth');
}
public function edit(Company $company, CompaniesController $companies)
{
$companies = $companies->getCompaniesName(Auth::user()->company_id);
$attributes = $company->attributes('company')
->where('attribute', '=', 'account_nr_start')
->get();
foreach ($attributes as $k => $v) {
$nr_start[] = $v->value;
}
return view('company.edit', ['company' => $company, 'id' => 'edit', 'companies' => $companies, 'nr_start' => $nr_start]);
}
public function update(UpdateCompanyRequest $request, $company, Attribute $attributes)
{
$company->fill($request->input())->save();
$attributes->fill($request->only('company_id', 'attribute_nr', 'value'))->save();
return redirect('company');
}
HTML/Blade:
<div class="form-group {{ $errors->has('_nr_') ? 'has-error' : '' }}">
{!! HTML::decode (Form::label('account_nr_start', trans('common.account_nr_start').'<span class="asterisk"> *</span>', ['class' => 'form-label col-sm-3 control-label text-capitalize'])) !!}
<div class="col-sm-6">
{!! Form::text('value', $nr_start[0], ["class"=>"form-control text-uppercase"]) !!}
{!! $errors->first('account_nr_start', '<span class="help-block">:message</span>') !!}
</div>
</div>
When I update a company now, it will upload like the last input here: :
So it makes a new rule, while it needs to edit the current attribute rule instead of making a new rule with an empty company_id/attribute.
If I understand what you are trying to do, I think this will fix your problem. The issue you have is the Attribute model is a new instance of the model rather than retrieving the model you need.
before running fill() from the attributes method try this
$new_attribute = $attributes->where('company_id', '=', $company->id)->where('attribute', '=', 'account_nr_start')->first();
Then run the fill()
$new_attribute->fill($request->only('company_id', 'attribute_nr', 'value'))->save();

Laravel - Resource route passing in wrong parametre (not the id)

I have an issue with my the update method in my controller.
Normally everything works and it takes care of itself, but this time its not working.
My controller:
public function update($id)
{
$input = Input::all();
$validation = Validator::make($input, Vehicle::$rules, Vehicle::$messages);
if ($validation->passes())
{
$this->vehicle->update($id, $input);
return Redirect::route('admin.vehicles.index')->with('success', 'Car Updated');
}
return Redirect::back()
->withInput()
->withErrors($validation);
}
Repository:
public function update($id, $input)
{
print_r($id);
die();
}
This prints out:
{vehicle}
from the URI:
http://localhost/admin/vehicles/1/edit
My form:
{{ Form::open(['route' => 'admin.vehicles.update', 'class' => 'form-horizontal edit-vehicle-form', 'method' => 'PATCH']) }}
// inputs
<div class="form-group">
{{ Form::submit('Update Vehicle', ['class' => 'btn btn-success']) }}
</div>
{{ Form::close() }}
Route:
Route::resource('/admin/vehicles', 'VehiclesController');
Where is this going wrong? How can I get this form to send the ID not the word vehicle?

Laravel 4.2 - Sentry - Not returning the correct view

I'm developing a CRUD app with Laravel 4.2 and using Sentry 2 for users registration and grouping. I created a model for animals and an AnimalController so Admin user can see/edit and delete animals from a DB. I've created all the views like: views/animales/create.blade.php. However when i try to call animales/create view to display the form to enter a new animal, I get an error exception thrown:
"Trying to get property of non-object (View: .../app/views/animales/show.blade.php)"
Which is actually not the view that I'm calling. Here are my routes:
Route::group(['before' => 'auth|admin'], function()
{
Route::resource('animales', 'AnimalController');
}
and here is my animal controller:
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');
}
}
Here is the filter file:
/*
|--------------------------------------------------------------------------
| 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;
}
});
And here is my 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>
Here is my create view:
<!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>
Can anyone help? Thanks!
Try this:
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 ));
}
So I was calling the same route (Route::resource('animales', 'AnimalController');) in another route group. Once I deleted the route from this other group, it worked. Anyway, thanks a lot for all the help!

Categories