partners I am having the following problem and I can not find the solution, I have a view with a form to register a user, which has the following dropdownlist
<select class="form-control" name="department_id" id="department_id">
@foreach($departments as $department)
<option value="{{$department->id}}">{{ $department->descripcion}}</option>
@endforeach
</select>
code that works, since the content is loaded to the select and I call the view in the following way:
public function create(){
$departments = Department::all();
$locations = Location::all();
return view('create')->with(compact('departments','locations'));
}
Now, when I submit to submit, I get Undefined variable: departments (View: ... \ resources \ views \ create.blade.php)
Why does it tell me that DEPARTMENTS is not defined in that view if the data is loaded to the select correctly? the problem arises when I click on the send button and I want to do the POST to register. I can not find the problem.
Edit: add store function in the controller
public function store(UserRequest $request)
{
$user = $request->all();
$user['password'] = Hash::make($user['password']);
User::create($user);
return view('create')->with('exito','Usuario dado de alta correctamente');
}