So, I got a Model
in Laravel 5.4 associated with a table and in my Model Controller, when I try to insert a register using $post->save();
the model registry is not being inserted at the database. I revised the code many times and even comparing it with other equal codes that works (although this other code is in L 5.3) and everythings seems to be Ok so I guess it is something happening at the database level that is making this registry not to be inserted. So, how can I get a possible, if it's the case, error message comming from MySql in this situation? Because, after I run the save()
method, nothing happens and I got no response. Thanks in advance
As suggested in the comments, I will post the complete code, however I still gottin no response from the Mysql level, the DB::enableQueryLog();
is still not writing to storage/logs/laravel.log:
The model:
class Post extends Model
{
protected $table = 'posts';
}
The Controller:
public function store(Request $request)
{
\DB::enableQueryLog();
$this->validate($request, array(
'assunto' => 'max:255',
'conteudo' => 'required|max:65535',
'arquivos[]' => 'required'
));
$post = new Post;
$post->assunto = Purifier::clean($request->assunto);
$post->board = Purifier::clean($request->nomeboard);
$post->conteudo = Purifier::clean($request->conteudo);
$post->sage = (Purifier::clean($request->sage) === "sage" ? 's' : 'n');
$post->lead = (Purifier::clean($request->insidepost) === "n" ? 'n' : 's');
$post->ipposter = $request()->ip();
//$post->datacriacao = Carbon::now();
//$post->ipposter = Request::ip();
if($post->save()){
$logfile = $this->iniciaLog('sucesso');
$this->escreveLog("info", "registro inserido", $logfile);
} else {
$logfile = $this->iniciaLog('falha');
$this->escreveLog("info", "erro ao inserir registro", $logfile);
}
$this->terminaLog($logfile);
return redirect()->route('/{nomeBoard}', $request->nomeboard);
}
The migration which defines the table:
Schema::create('posts', function (Blueprint $table) {
$table->increments('id');
$table->string('assunto', 256);
$table->string('board', 10);
$table->text('conteudo');
$table->char('sage', 1);
$table->char('lead', 1);
$table->string('ipposter', 15);
$table->timestamps();
});
via Fabiotk