Search
 
SCRIPT & CODE EXAMPLE
 

PHP

laravel return data from model to another controller

Relation : Parent has many Childrens

ParentController:
	use AppModelsChildren;

    public static function showChildrens($parent_id) {
        $children = new Children;
        $childrens = $children->scopeShow($parent_id);
        return compact('childrens');
    } 



Children Model:
	use AppModelsParent;

	public function parent() {
        return $this->belongsTo(Parent::class);
    }

    public static function scopeShow($parent_id) {
        $childrens = Children::where('parent_id', $parent_id)->get();
        return $childrens;
    }

// Note: Don't use the word "parent" in your app as table it will sometimes create conflicts, this was just for the example
// Like the post if you found it usefull and help other devs to find the good answer
Comment

PREVIOUS NEXT
Code Example
Php :: what is composer in laravel 
Php :: laravel firstorcreate usage 
Php :: static function php 
Php :: activerecord yii2 select with limit(start,end) not working 
Php :: wp wc php if not is single product page 
Php :: Calculate Math Expression From A String Text With PHP 
Php :: laravel collection flatMap 
Php :: laravel password test 
Php :: symfony append to file 
Php :: try_files $uri $uri/ /index.php?$query_string; 
Php :: console_log in php 
Php :: + php quantifer 
Php :: php command line check syntax errors 
Php :: carbon now set timezone 
Php :: octobercms mail view 
Php :: get chmod of directory php 
Php :: drupal show php errors 
Php :: blade check user role laravel 
Php :: hasmany relationship in laravel 
Php :: run phpstan terminal 
Php :: table laravel 
Php :: php else 
Php :: Fetch pivot data laravel 
Php :: create qr code png image of 200*200 using phpqrcode 
Php :: remove field from object php 
Php :: php find all subclasses of class 
Php :: laravel telescope tutorial 
Php :: mac os down upgrade php version 
Php :: php get last 3 elements of array 
Php :: laravel env use other env variables 
ADD CONTENT
Topic
Content
Source link
Name
6+3 =