I'm having a problem with my model, I do not really know what's going on, I'm creating a packaging CRUD where I add everything dynamically with the laravel by the requests in the function signature.
When trying to edit / view / delete my controller returns empty, as if I was accessing an empty model. No mistakes are coming back empty. To test I listed all the packages already registered and worked perfectly.
My files are structured as follows:
CONTROLLER PACKAGING
public function index(){
$embalagens = Embalagem::all();
if(Request::wantsJson()){
return $embalagens;
}else{
return view('Embalagem.listEmbalagem', compact('embalagens'));
}
}
public function create(){
$embalagem = new Embalagem();
return view('Embalagem.cadEmbalagem', compact('embalagem'));
}
public function store(EmbalagemRequest $resquest){
$embalagem = Embalagem::create($resquest->all());
$embalagens = Embalagem::all();
if(Request::wantsJson()){
return $embalagem;
}else{
return view('Embalagem.listEmbalagem', compact('embalagens'));
}
}
public function show(Embalagem $embalagem){
if(Request::wantsJson()){
return $embalagem;
}else{
return view('Embalagem.showEmbalagem', compact('embalagem'));
}
}
public function edit(Embalagem $embalagem){
return view('Embalagem.editEmbalagem', compact('embalagem'));
}
public function update(EmbalagemRequest $request, Embalagem $embalagem){
$embalagem->update($request->all());
$embalagens = Embalagem::all();
if(Request::wantsJson()){
return $embalagem;
}else{
return view('Embalagem.listEmbalagem', compact('embalagens'));
}
}
public function destroy(Embalagem $embalagem){
$deleted = $embalagem->delete();
$embalagens = Embalagem::all();
if(Request::wantsJson()){
return (string) $deleted;
}else{
return view('Embalagem.listEmbalagem', compact('embalagens'));
}
}
MODEL PACKING
namespace App;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class Embalagem extends Model
{
use SoftDeletes;
protected $fillable = ['NmEmbalagem', 'DscEmbalagem', 'UnitEmbalagem'];
protected $primaryKey = 'CdEmbalagem';
protected $dates = ['deleted_at'];
}
REQUEST PACKING
public function authorize()
{
return true;
}
public function rules()
{
return [
'NmEmbalagem' => 'required|min:1',
'DscEmbalagem' => 'required|min:5'
];
}
MY ROUTES
Route::singularResourceParameters();
Route::group(['middleware' => ['web']], function (){
Route::resource('clientes', 'ClienteController');
Route::resource('categorias', 'CategoriaController');
Route::resource('embalagens', 'EmbalagemController');
});
| | POST | embalagens | embalagens.store | App\Http\Controllers\EmbalagemController@store | web,web |
| | GET|HEAD | embalagens | embalagens.index | App\Http\Controllers\EmbalagemController@index | web,web |
| | GET|HEAD | embalagens/create | embalagens.create | App\Http\Controllers\EmbalagemController@create | web,web |
| | PUT|PATCH | embalagens/{embalagen} | embalagens.update | App\Http\Controllers\EmbalagemController@update | web,web |
| | DELETE | embalagens/{embalagen} | embalagens.destroy | App\Http\Controllers\EmbalagemController@destroy | web,web |
| | GET|HEAD | embalagens/{embalagen} | embalagens.show | App\Http\Controllers\EmbalagemController@show | web,web |
| | GET|HEAD | embalagens/{embalagen}/edit | embalagens.edit | App\Http\Controllers\EmbalagemController@edit | web,web |
MY MIGRATION
public function up()
{
Schema::create('embalagems', function (Blueprint $table) {
$table->increments('CdEmbalagem');
$table->string('NmEmbalagem');
$table->string('DscEmbalagem');
$table->string('UnitEmbalagem');
$table->timestamps();
$table->softDeletes();
});
}
What can be happening? Is something missing that I can not see?