2016-07-27 6 views
1

私は、コントローラメソッドに注入されたEloquentを使用してモデルを取得することに問題があります - それはURLでIDを使用してモデルを見つけることができません。私はメソッドへのEloquent model注入がnullを返す

DB::setFetchMode(PDO::FETCH_ASSOC); 

DD($インフラストラクチャ)を返すだけのメタデータモデルについては、他のコントローラに変更されたことを覚え :

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

私のコントローラメソッド:

public function show(Infrastructure $infrastructure) 
{ 

    $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')); 
} 

マイ路線:

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


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


Route::get('auth/logout', 'Auth\[email protected]'); 

});

答えて

0

へのインフラ/ {インフラ} /ログ "にワイルドカードを変更します。

0

経路ファイルの変更Route::model('infrastructure', 'App\Infrastructure');Route::bind('infrastructure', 'App\Infrastructure');

+0

いいえ、それでも同じ –

0

Route ::リソースはワイルドカードを「インフラストラクチャ」にする複数の名前を持つワイルドカードを定義します。

モデルに 'インフラストラクチャ'ワイルドカードをバインドしています。これは、showInfrastructureLogメソッドでのみ機能します。

あなたは、各リソースのフルパスを表示するには、コンソールでこのコマンドを使用することができます。

php artisan route:list 

あなたは簡単に

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

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

を変更することでこの問題を解決することができます(私はモデルバインディングのためにRoute :: modelを個人的に使用したことはありません。常にRouteServiceProviderから行いましたが、それはうまくいくと思います)

また、私は、これは

php artisan route:clear 
php artisan route:cache 

が働いて働いたがruuning停止した理由はわかりません「インフラ」

+0

私は何が何に変わるのかを理解していませんでした。あなたは同じ行に書きました。 –

+1

Route :: model( 'インフラストラクチャ'、 'App \ Infrastructure');もう1つ、私の悪い – Shipupi

関連する問題