is that possible to use direct table name in hasMany. for example
public function Permissions()
{
return $this->hasMany('TABLE NAME');
}
I have table named PERMISSION but don't have a model of this table, but i want to use this table in hasmany.
Relations in Laravel are a part of Eloquent ORM which is built on the use of models.
So, no, it is not possible to use relations without making models for them.
Just create a model for that table
php artisan make:model Permisson
then add the table name to the model class
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Permisson extends Model
{
protected $table = "table_name";
}
and add the relation
public function permissions()
{
return $this->hasMany(Permisson::class)
}
I hope it helps
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With