i am new to laravel
this is my code for controller
I am writing a code to save the data from the user in Mysql And then redirect me to the list page with updated table and a flash message that the data has been updated successfully
i also tried using session->('key') but it didn't work
<?php
namespace App\Http\Controllers;
use App\restaurent_name;
use Illuminate\Http\Request;
class RestaController extends Controller
{
function Index()
{
return view('home');
}
function list()
{
$data = restaurent_name::all();
return view('list',["Data"=>$data]);
}
function add(Request $req)
{
//return $req->input();
$save = new restaurent_name;
$save->name=$req->input("name");
$save->address=$req->input("address");
$save->contact=$req->input("contact");
$save->save();
$save->session()->has('status');
//$save->session()->put('status', 'Task was successful!');
//$save->session()->flash('status','Restaurent added succesfully');
return redirect('/list');
}
}
the data gets saved properly into the database but the issue is that i am not able to receive message from flash session
This the error message i receive when i try to use flash session
`
Illuminate\Database\Eloquent\Model::throwBadMethodCallException C:\xampp\htdocs\Laravel
Projects\Restaurants\vendor\laravel\framework\src\Illuminate\Support\Traits\ForwardsCalls.php:50
$pattern = '~^Call to undefined method (?P<class>[^:]+)::(?P<method>[^\(]+)\(\)$~';
if (! preg_match($pattern, $e->getMessage(), $matches)) {
throw $e;
}
if ($matches['class'] != get_class($object) ||
$matches['method'] != $method) {
throw $e;
}
static::throwBadMethodCallException($method);
}
}
/**
* Throw a bad method call exception for the given method.
*
* @param string $method
* @return void
*
* @throws \BadMethodCallException
*/
protected static function throwBadMethodCallException($method)
{
throw new BadMethodCallException(sprintf(
'Call to undefined method %s::%s()', static::class, $method
));
}
}
`
$save->session()->has('status');
you want to pass a flash message? – stareturn redirect('/list')->with('status', 'Restaurent added succesfully');
– sta