I am working on the access and permissions for users in my laravel project i want to display the function of the modules so i can add them to a certain role here is my database :
public function up()
{
Schema::create('role_modules', function (Blueprint $table)
{
$table->increments('id');
$table->integer('rang');
$table->string('title');
$table->string('route');
$table->text('description');
$table->softDeletes();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('role_modules');
}
public function up()
{
Schema::create('role_functions', function (Blueprint $table)
{
$table->increments('id');
$table->integer('module_id')->unsigned();
$table->string('title');
$table->string('function');
$table->softDeletes();
$table->timestamps();
$table->foreign('module_id')->references('id')->on('role_modules')->onDelete('cascade');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('role_functions');
}
and here is my models code:
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Rolemodules extends Model
{
protected $table = 'role_modules';
public function func()
{
return $this->hasMany('App\Rolefunctions','module_id');
}
}
When i want to display the functions of each module in my view like this :
@foreach($rolemodules as $rolemodule)
{{$rolemodule->func['title']}}
@endforeach
I get this error: Undefined index: title