I already define the variable here is my code
class MainController extends Controller
{
public function index()
{
$country = Country::all();
return view ('index',compact($country));
}
public function getStates($id)
{
$states = State::where('country_id', $id)->pluck("name", "id");
return json_encode($states);
}
}
CodePudding user response:
you can do any of the following
1.
public function index()
{
$country = Country::all();
return view('index',compact('country'));
}
public function index()
{
$country = Country::all();
return view('index',['country' => $country]);
}
CodePudding user response:
when use compact write data withoute $
and put it in ''
:
public function index()
{
$country = Country::all();
return view ('index',compact('country'));
}