mercredi 27 juillet 2016

Eloquent\model injection into method returns null

I have problem with fetching model using injected Eloquent into controllers method - it dosne't find model using id in URL - dd($infrastructure) returns just meta data about Model:

Infrastructure {#257 ▼
#table: "infrastructures"
#fillable: array:10 [▶]
#connection: null
#primaryKey: "id"
....
} 

My controllers method:

public function show(Infrastructure $infrastructure, Request $request)
{

    $card = [];
    $card['name'] = $infrastructure->name;
    $card['id'] = $infrastructure->id;
    $card['type'] = "infrastructure";
    $card['items']['manufacturer'] = $infrastructure->manufacturer;
    $card['items']['type'] = $infrastructure->infrastructuretype()->first()-   >name;
    $card['items']['kind'] = $infrastructure->kind()->first()->name;
    $card['items']['serial'] = $infrastructure->serial;
    $card['items']['more info'] = Crypt::decrypt($infrastructure->long_desc);

    $title = 'Infrastructure details ';

    $warranty_left = $infrastructure->warranty_date > $infrastructure->purchase_date ? (new Carbon($infrastructure->warranty_date))->diffInDays(new Carbon($infrastructure->purchase_date)) : 0;

    return view('infrastructure.show', compact('infrastructure', 'card', 'title'));
}

My routes:

Route::model('infrastructure', 'App\Infrastructure');


Route::group(['middleware' => 'auth'], function () {
Route::resource('infrastructure', 'InfrastructureController');
get('infrastructure/{infrastructure}/logs', [
    'uses' => 'InfrastructureController@showInfrastructureLogs'
]);
resource('infrastructuretype', 'InfrastructureTypeController');


Route::get('auth/logout', 'Auth\AuthController@getLogout');

});



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire