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 :: php array_map passing parameters 
Php :: array_search 
Php :: laravel url previous 
Php :: codeigniter 4 redirect to home 
Php :: php date strtotime format 
Php :: php keep only letters and numbers 
Php :: laravel required only one of multiple fields not both 
Php :: php remove charictors from a string 
Php :: laravel orderby with relation 
Php :: CodeIgniter get_where order_by 
Php :: how to create shortcode 
Php :: open php tag 
Php :: carbon random future date 
Php :: global laravel request() 
Php :: update-alternatives java 
Php :: PHP Max Input Vars 
Php :: php date is before 
Php :: lumen generate app key 
Php :: table drop foreign php laravel 
Php :: php write to file 
Php :: php routing 
Php :: php mkdir 
Php :: how to set a validation on a value if its not null in laravel php 
Php :: laravel log daily 
Php :: php change string to url friendly 
Php :: php get start of today 
Php :: branch from other branch 
Php :: how to separate integer from string in php 
Php :: how to save file in storage folder in laravel 
Php :: laravel eloquent where id not equal to 
ADD CONTENT
Topic
Content
Source link
Name
1+2 =