-1

I am new to laravel and i cannot understand the following code while learning laravel i know that we use '::' to call the static function of a class but using '->' after calling the static function creates confusion for me

use App\Post;
 Route::get('/forcedelete', function () {
     Post::withTrashed()->where('id',1)->forcedelete();
 });;

1 Answers1

0

This line is a chained call. The following code would have the same result:

$query = Post::withTrashed();
$query = $query->where('id', 1);
$query->forceDelete();

The first line returns a Builder|Model instance (docs), so when you want to use it (second line), you're not in a static context anymore so you have to use the arrow.

SystemGlitch
  • 2,150
  • 12
  • 27