laravel-4

How do I use a package language file?

回眸只為那壹抹淺笑 提交于 2019-12-05 04:03:22
I'm trying to use a Laravel 4 package language file, but I don't know how to do it. I created a package with php artisan workbench vendor/package --resources . I then create file workbench/vendor/package/src/lang/en/routes.php . In that routes file a I have this: <?php return [ 'foo' => 'bar' ]; Now how do I access that? I tried with Lang::get('routes.foo') and Lang::get('vendor/package::routes.foo') but both fails and just gives me the parameter itself I entered. I'm calling it in my service providers boot method. antoniputra Same like you call view and config: // for lang Lang::get('package:

Route to controller in subfolder not working in Laravel 4

被刻印的时光 ゝ 提交于 2019-12-05 03:28:04
I was updating my Laravel 3 app to Laravel 4 when I hit this problem... Routes I have tried: Route::get('backend/login', 'backend/UserController@login'); Route::get('backend/login', 'backend.UserController@login'); I had a similar issue just a few hours ago and had to play a little bit with it to have it working. Routes: Route::group(array('prefix' => 'admin'), function() { Route::resource('/', 'admin\DashboardController'); }); In "controllers/admin" i put the DashboardController: namespace admin; use Illuminate\Support\Facades\View; class DashboardController extends \BaseController { public

Populating a dropdown menu with database results in Laravel 4

≡放荡痞女 提交于 2019-12-05 03:19:31
I'm trying to populate a drop down menu with database results in Laravel 4. I'm extremely new to Laravel. This is actually my first site and I'm learning as I go. So, please tell me if I'm using the wrong terminology or not enough information. I've got a database of company info and I need users to be able to choose a company from a dropdown. Or if the company isn't in the database to add it. For the select menu, it needs to go like this: [company name result] And I'm using this code in my controller: $companies = RecordCompany::get(); $company_selector = array(); foreach($companies as

Override section in a laravel blade template throwing undefined variable errors

青春壹個敷衍的年華 提交于 2019-12-05 03:15:31
问题 I am using Laravel 4 and blade templates, and running into an issue when I try and extend a template. In my layout I have @yield('content') and in my page I have @section('content') Welcome {{ $name }} @stop which works fine, I've created another page very similar to my first, and just want to change override the admin content section. The other sections in the template are fine. so I extend my page, and do @section('content') Hello! @stop I get an undefined notice with the $name variable. I

Multiple Where In

↘锁芯ラ 提交于 2019-12-05 03:06:10
I'm using eloqent to filter a set of products: Product::whereIn('color', $color)->whereIn('size', $size)->whereIn('price', $price)->get(); Each of the above variables is an array of ids $color = [1,2,4,5] My question is, is this inefficient when the user fails to send through a set of variables, say they did not want any color filters so the array would be: $color = []; I've tried ->toSql and it produces the sql statement: select * from `products` where `color` in (?, ?) and 0 = 1 and `price` in (?, ?, ?, ?, ?) In the above no size filter has been sent through. What does 0 = 1 mean? And is

Laravel pre-filling multiple forms if validation failed

浪尽此生 提交于 2019-12-05 03:02:33
问题 One of the coolest Laravel feature is, Laravel pre-filled the form fields if validation error occurred. However, if a page contain more than one form , and form fields have same name , Laravel pre-filling all forms fields . For example: I have a page where i have two forms to create new users or whatever. <h1>Create user1</h2> {{ Form::open(array('url' => 'foo/bar')) }} {{ Form::text('name', null) }} {{ Form::email('email', null) }} {{ Form::close() }} </h1>Create user2</h1> {{ Form::open

Laravel Eloquent, select only rows where the relation exists

妖精的绣舞 提交于 2019-12-05 03:02:29
I am trying to select from a table, but I only want to select things that have an existing relationship. For example, if I have Users and Comments, and Users haveMany Comments, I want to do something like: User::hasComments()->paginate(20); So, I only want to select Users that have at least 1 Comment, and paginate the result of that query. Is there any way to do this? According to Laravel's Eloquent documentation for querying relations (look for the "Querying Relationship Existence" subheading), this should work: User::has('comments')->paginate(20); Flip your thinking upside down and I think

Mcrypt PHP extension required in Laravel [duplicate]

落花浮王杯 提交于 2019-12-05 02:29:34
问题 This question already has answers here : Laravel requires the Mcrypt PHP extension (22 answers) Closed 2 years ago . I'm trying to install Laravel on Linux Ubuntu. I'm running Ubuntu 14.10. Everything worked alright. But now instead of getting the supposed page when accessing localhost I get the message: " Mcrypt PHP extension required " I'm copying some information from terminal to help pinpoint the problem. which php /usr/bin/php php --ini Configuration File (php.ini) Path: /etc/php5/cli

How to use storage_path() to view an image in laravel 4

大憨熊 提交于 2019-12-05 02:07:12
问题 I'm using storage_path() for storing uploaded images, but when I use it is pointing wrong on my page. I use it like this {{ $data->thumbnail }} where $data came from the database and thumbnail comes as the string which used storage_path 回答1: Let us take a look at the default L4 application structure: app // contains restricted server-side application data app/storage // a writeable directory used by L4 and custom functions to store data ( i.e. log files, ... ) public // this directory is

Laravel: how to add where clause using query builder?

雨燕双飞 提交于 2019-12-05 02:06:09
I have this query, made using Laravel query builder: $rows = DB::table('elements')->where('type', 1); That corresponds to: "SELECT * from elements WHERE type=1" Now, in some cases I need to add a second Where to create a query like this: SELECT * from elements WHERE type=1 AND lang='EN' Using classic php I'd do something like: $sql = 'SELECT * from elements WHERE type=1'; if($var==true) $sql .= " AND lang='EN'"; How can I do that using Laravel Query Builder? Thank you. The Alpha You may try something like this $query = DB::table('elements'); $query->where('some_field', 'some_value'); //