i have an issue with Laravel 5 Route Model Binding I am using the following Controller Method
public function destroy(PrimaryLocation $primaryLocation) {
dd($primaryLocation->id);
$primaryLocation->delete();
return redirect()->back()->with('locationDeleted', true);
}
Where PrimaryLocation is an Eloquent Model
My RouteServiceProvider's boot function:
public function boot(Router $router)
{
parent::boot($router);
$router->model('user', 'App\User');
$router->model('PrimaryLocation', 'App\PrimaryLocation');
}
And in my routes.php
Route::delete('deletePrimaryLocation/{PrimaryLocation}',
['as' => 'admin.deletePrimaryLocation', 'uses' => 'LocationsController@destroy']);
This setup works fine on my local Computer, but when i deploy the files to my development server, somwhere the model binding breaks; The Location won't get deleted on executing the method.
I did some var_dumps
dd($primaryLocation->id);
on local computer this returns the correct id, but on the server it will just return null;
However if I do a
dd($primaryLocation)
The result is locally
PrimaryLocation {#178 ▼
#fillable: array:1 [▶]
#connection: null
#table: null
#primaryKey: "id"
#perPage: 15
+incrementing: true
+timestamps: true
#attributes: array:4 [▶]
#original: array:4 [▶]
#relations: []
#hidden: []
#visible: []
#appends: []
#guarded: array:1 [▶]
#dates: []
#casts: []
#touches: []
#observables: []
#with: []
#morphClass: null
+exists: true
}
On on my Server nearly the same... but the attributes are missing:
PrimaryLocation {#195 ▼
#fillable: array:1 [▶]
#connection: null
#table: null
#primaryKey: "id"
#perPage: 15
+incrementing: true
+timestamps: true
#attributes: []
#original: []
#relations: []
#hidden: []
#visible: []
#appends: []
#guarded: array:1 [▶]
#dates: []
#casts: []
#touches: []
#observables: []
#with: []
#morphClass: null
+exists: false
}
Does anyone have a clue what might be going wrong?
[UPDATE]
if I comment out
// $router->model('PrimaryLocation', 'App\PrimaryLocation');
In me ServiceProvider, the local behaviour is the same as on the server. Maybe there's something wrong with loading the ServiceProvider? Maybe there is some sort of cache?
attributesis because it cannot find the record. Is the data the same in the database? i.e. same database, tables and fields? Specifically - does the record itself exist?PrimaryLocation.phpwith the case sensitivity the same?nullfor theidis proof of that. Plus when youdd()the object you can clearly seeexists: false. So we need to confirm the record is actually in the database - then work it out from there.