I'm trying to send a success message with a compact but it didn't work for me a message does not appear?
public function index(Request $request)
{
$brand=$request->get('searchbrand');
$model=$request->get('searchmodel');
$cars=car::where('brand','like','%'.$brand.'%')
->where(function ($query)use($model) {
$query->where('model','like','%'.$model.'%');
})->get();
return view('cars.index',compact('cars'))
->with('success','Results Car');
}
You can use compact()
or with()
, but generally not both.
Here's some options:
->with()
with a single array
:return view('cars.index')->with(['cars' => $cars, 'success' => 'Results Car']);
->with()
calls:return view('cars.index')->with('cars', $cars)->with('success', 'Results Car');
array
instead of with()
or compact()
:return view('cars.index', ['cars' => $cars, 'success' => 'Results Car']);
compact()
with a $success
variable:$success = 'Results Car';
return view('cars.index', compact('cars', 'success'));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.