I have two queries regarding the use of "use" keyword in php(laravel).
Below is a code excerpt from laravel docs:
use App\Flight;
$flights = App\Flight::all();
foreach ($flights as $flight) {
echo $flight->name;
}
The code in line 1 allows us to use Flight model and line 2 has a statement which fetches all the records. So, in line 2 cannot we just say Flight::all();
instead of App\Flight::all();
. Are both correct and does it relate to relative and absolute path stuff?
Second Query(related to softDeletes): Below is a code block from one of my models:
namespace App;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class Post extends Model
{
use SoftDeletes;
protected $dates = ['deleted_at'];
protected $fillable = ['title','body'];
}
Here on line 6, the following statement is used:
use SoftDeletes;
Why are we again using use keyword with softDeletes
because we didn't use that with model and simply we could do :
class Post extends Model
without the following code statement:
use Model;
in case of models.