0 レビュー
1 回答
php-Laravelパッケージ内のコントローラーアクションにパラメーターを渡すにはどうすればよいですか?
私が作成したLaravelパッケージ内で、(同じパッケージ内の)パラメーターを必要とするコントローラーアクションにユーザーをリダイレクトしたいと思います。
コントローラー:
public function postMatchItem(Request $request, $id)
{
$this->validate($request, [
'item_match' => 'required|numeric|exists:item,id',
]);
$spot_buy_item = SpotBuyItem::find($id);
$item = Item::find($request->input('item_match'));
$price = $item->getPrice();
$spot_buy_item_response = new SpotBuyItemResponse();
$spot_buy_item_response->spot_buy_item_id = $id;
$spot_buy_item_response->spot_buy_id = $spot_buy_item->spot_buy_id;
$spot_buy_item_response->item_id = $item->id;
$spot_buy_item_response->user_id = $spot_buy_item->user_id;
$spot_buy_item_response->spot_buy_price = $price;
$spot_buy_item_response->created_ts = Carbon::now();
$spot_buy_item_response->save();
return redirect()->action('Ariel\SpotBuy\Http\Controllers\Admin\[email protected]', [$id]);
}
リダイレクトのアクションは、 routes.php
ファイルでユーザーをこのコントローラーアクションに誘導するために使用するのと同じパスです
ルート:
Route::get('/part/{id}', 'Ariel\SpotBuy\Http\Controllers\Admin\[email protected]')->where('id', '[0-9]+');
ドキュメントが示唆しているように[email protected]
を含め、このパスのバリエーションを試しましたが成功しませんでした( https://laravel.com/docs/5.1/responses#リダイレクト)
注:ルートに routes.php
で名前を付け、 return redirect()->route('route_name', [$id]);
を使用することで、これを機能させることができました。 、しかし、パッケージコントローラーアクションを ->action()
関数に渡す方法を知りたいです。
わからない
0
レビュー
答え :
解決策:
App\Http\Controllers
名前空間内からコントローラーにアクセスしようとしています。エラーでコントローラー名に追加されたことがわかります:
App\Http\Controllers \ Ariel \ SpotBuy \ Http \ Controllers {-code-4 } Admin \ SpotBuyController @ getP art
最初に\
を使用して、 Ariel
名前空間をエスケープする必要があります。
return redirect()-> action('\ Ariel \ SpotBuy \ Http \ Controllers {- code-4} Admin \ SpotBuyController @ getPart'、[$ id]);
わからない
同様の質問
私たちのウェブサイトで同様の質問で答えを見つけてください。