public function create()
{
return view('curso.create');
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$cursos = new Curso([
'nome' => $request->get('nome')
]);
$cursos->save();
return redirect('/cursos');
}
public function edit($id)
{
$cursos = Curso::find($id);
return view('curso.edit', compact('cursos','id'));
}
And here my view create.blade.php
@extends('master')
@section('content')
<div class="container">
<h2>Cadastrar Curso</h2>
<form method="post" action="{{action('CursoController@store')}}">
<div class="form-row">
{{csrf_field()}}
<div class="form-group col-md-12">
<label for="lgFormGroupInput">Nome</label>
<input type="text" class="form-control" id="lgFormGroupInput" placeholder="Nome do Curso" name="nome">
</div>
</div>
<div class="form-row">
<div class="col-md-5"></div>
<input type="submit" class="btn btn-primary">
<a class="btn btn-danger" href="{{ action('CursoController@index') }}"> Cancelar</a>
</div>
</form>
</div>
@endsection
here is my edit.blade.php
@extends('master')
@section('content')
<div class="container">
<h2>Editar Curso</h2>
<form method="post" action="{{action('CursoController@update', $id)}}">
<div class="form-group row">
{{csrf_field()}}
<input name="_method" type="hidden" value="PATCH">
<label for="lgFormGroupInput" class="col-sm-2 col-form-label col-form-label-lg">Nome</label>
<div class="col-sm-10">
<input type="text" class="form-control form-control-lg" id="lgFormGroupInput" placeholder="Nome" name="nome" value="{{$cursos->nome}}">
</div>
</div>
<div class="form-group row">
<label for="lgFormGroupInput" class="col-sm-2 col-form-label col-form-label-lg">Professor</label>
<div class="col-sm-10">
<input type="text" class="form-control form-control-lg" id="lgFormGroupInput" placeholder="Nome" name="nome" value="{{$cursos->professor->nome}}">
</div>
</div>
<div class="form-group row">
<div class="col-md-2"></div>
<button type="submit" class="btn btn-primary">Editar</button>
<a class="btn btn-danger" href="{{ action('CursoController@index') }}"> Cancelar</a>
</div>
</form>
</div>
@endsection
I need to change this teacher to a select.