There is an error in Laravel 5.6 when I try to check is a model empty with isEmpty function.
Model:
namespace App\Models\Projectmanagement;
use Illuminate\Database\Eloquent\Model;
class Projects extends Model
{
protected $table = 'projects';
public $timestamps = false;
}
Controller:
public function create()
{
$project = new Projects;
return view('pages.projectmanagement.projects.edit', [
'project' => $project,
'companies' => Company::all(),
]);
}
View:
<form method="post">
{{ csrf_field() }}
@if($project->isEmpty())
@method('PUT')
@endif
</form>
The idea is that I reuse edit.blade view file for creating and updating data, so I need to check if a model is empty to make proper changes in the view file.
But in this case, Laravel 5.6 throws an error:
Method Illuminate\Database\Query\Builder::isEmpty does not exist. (View: /var/www/resources/views/pages/projects/edit.blade.php)