user3650015
user3650015

Reputation: 1

Pass parameters to Models in Laravel

I'm new in Laravel I need help in passing variables to models/model methods

In codeigniter I do this

$this->model_name->model_method($variable_name);

How can I translate this in Laravel syntax?

Upvotes: 0

Views: 125

Answers (1)

Antonio Carlos Ribeiro
Antonio Carlos Ribeiro

Reputation: 87719

Laravel 4 uses exactly the same syntax, but methods are camel cased:

$this->model_name->modelMethod($variable_name);

Taking from the comments, this is how you should be doing your scopes:

public function scopeTestMethod($query, $user) 
{ 
    return $query->where('user', $user); 
}

To

$posts = Post::TestMethod($user)->get();

or

$test = Post::query(); 

$test = $test->TestMethod($user)->get();

Take a look at the Laravel docs: http://laravel.com/docs/eloquent#query-scopes

Upvotes: 1

Related Questions