PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, October 21, 2022

[FIXED] How to use table without model in hasMany

 October 21, 2022     eloquent, has-many, laravel     No comments   

Issue

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.


Solution

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



Answered By - larsbadke
Answer Checked By - Senaida (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing