Skip to content
Advertisement

laravel 5 get current language id in controller

i’m new to laravel, and i’m wondering how to get the language_id (primary key “id” in database) by current lang_code (a column of language table).

in my language model, i created a function like this :

JavaScript

in the homeController, i added this line of code:

JavaScript

Got errors:

JavaScript

edit The actual things i want to do is:

JavaScript

edit

What is the problem? And what is the best practice to get the id ? i know the above code should not be good in practice.

Advertisement

Answer

You can use Query scope in laravel 5

Model

JavaScript

Controller

JavaScript

More details about Query Scope: http://laravel.com/docs/5.0/eloquent#query-scopes

Is this what you are looking for?

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement