php - Laravel Undefined variable when passing variable -
beginner question :
i'm passing $wordsrow variable wordscontroller results2 blade. $wordsrow contains row in words table.
wordscontroller code :
$wordsrow = words::where(db::raw('body'),'like', "%{$body}%")->get(); return view('results2', [ 'message' => $message , 'wordsrow' => $wordsrow]);
and in results2 blade, passing body , id columns of wordsrow dashboard2 blade.
@if (isset($wordsrow)) @foreach ($wordsrow $wordsrow) <a href="{{route('dashboard2',[ 'wordsrowb'=>$wordsrow->body, 'wordsrowid'=>$wordsrow->id])}}">{{$wordsrow->body}}</a> <br> @endforeach @endif
and in dashboard2 blade, have problem follows :
if use form empty action <form action="#" method="post">
, no issues occur, , dashboard view opens no problems. while if use :
<form action="{{route('post.create',['wordid' => $wordsrowid])}}" method="post">
i receive following error :
errorexception in aadedc1cbff958325ddae8e9ce9778562c4daf4a.php line 83: undefined variable: wordsrowid (view: d:\wamp\www\xxxxx\resources\views\dashboard2.blade.php)
any ?
the problem in route gerard reches mentioned.
i modified dashboard2 route hold 2 variables, , modified controller recieve 2 variables , return them dashboard2 view, follows :
controller code :
public function getdashboard($wordsrowid, $wordsrowb) { $posts = post::orderby('created_at', 'desc')->get(); //$posts=post::all(); //return view('dashboard'); return view('dashboard2', [ 'posts' => $posts, 'wordsrowb'=> $wordsrowb , 'wordsrowid'=> $wordsrowid ]); }
route code :
route::get('/dashboard2/{wordsrowb}/{wordsrowid}', [ 'uses' => 'dashcontroller@getdashboard', 'as' => 'dashboard2', 'middleware' => 'auth' ]);
Comments
Post a Comment