laravel-4

Laravel 4: can one model serve several DB tables?

徘徊边缘 提交于 2019-12-19 04:15:18
问题 In my application I have several mysql tables: Toronto, Vancouver, Montreal, etc... and I am using the DB-class to work with them, eg. $data = DB::select('select * from toronto where id = ?', array($id)); What I want to do is to start using Eloquent. I am new to Laravel and was just wondering if its possible to have one model work with several tables, smth like: class City extends Eloquent { protected $table_a = 'toronto'; protected $table_b = 'vancouver'; protected $table_c = 'montreal'; }

How to implement Laravel 4 Partial Views - Binding data to partial views

和自甴很熟 提交于 2019-12-19 04:07:08
问题 I am debating whether I should use Laravel to build an online store. Requirement - Show a shopping cart in sidebar with product listing in main area. i need to bind data to my partial views. I have created a PartialController to display partial views. class PartialController extends BaseController { public function showCartSummary() { $cartItems = Cart::all(); return View::make('partials.cartsummary', array( 'cart' => $cartItems, )); } public function showProducts() { $products = Products:

Set locale on the fly in laravel4

点点圈 提交于 2019-12-19 03:20:51
问题 After searching through the documentation from laravel 4 I see that the way to set a language is to do App::setLocale('en'); But how do I use this in combination with for example a language switcher on my website that a visitor can click on to change the language on the fly? and to remember this with a cookie or something? It seems that in laravel 3 it was much easier but since im new to laravel I don't know how to figure this out so if someone knows what to do and can help me out it would be

Laravel Bulk UPDATE

被刻印的时光 ゝ 提交于 2019-12-19 03:12:34
问题 I'm trying to update a table containing a slug value with random slugs for each record. $vouchers = Voucher->get(); // assume 10K for example foreach ($vouchers as $voucher) { $q .= "UPDATE vouchers set slug = '" . Str::random(32) . "' WHERE id = " . $voucher->id . ";"; } DB::statement($q); There are about 2 million records so I need to perform this as a bulk. Doing it as separate records is taking way too long. I can't seem to find a way to bulk run them, say in groups of 10K or something.

Redirect www to non-www in Laravel with URL parameters

一笑奈何 提交于 2019-12-19 02:54:31
问题 How can I redirect URL from www.myapp.co to myapp.co ? And also if the URL has other parameter like www.myapp.co/other-parameter will be redirected to myapp.co/other-parameter where the other-parameter can be anything. Sorry for this noob question, I am still 1 week in using Laravel. BTW, I am using dynamic subdomain so I need only the redirect www to non-www and not the other subdomains. Route::group(array('domain' => 'myapp.co'), function() { Route::get('/', function() { return 'Hello!

nginx rewrite post data

杀马特。学长 韩版系。学妹 提交于 2019-12-19 02:39:13
问题 I need to preserve the POST data to a different url The rewrite works but the post data is lost need to post data from user_info.php to userhistory location ~ user_info.php { rewrite ^/.* http://testing.com/userhistory permanent; } The data is lost. How can I preserve the data? 回答1: Basically, you want to automatically redirect a POST request using a 301 Moved Permanently redirect. However. such redirect are specifically disallowed by the HTTP Specifications which states that: If the 301

Laravel form won't PATCH, only POST - nested RESTfull Controllers, MethodNotAllowedHttpException

天涯浪子 提交于 2019-12-19 02:26:12
问题 I am trying to allow users to edit their playlist . However, whenever I try to execute the PATCH request, I get the MethodNotAllowedHttpException error. (it is expecting a POST) I have set up RESTful Resource Controllers: Routes.php: Route::resource('users', 'UsersController'); Route::resource('users.playlists', 'PlaylistsController'); This should give me access to: (as displayed through php artisan routes ) URI | Name | Action PATCH users/{users}/playlists/{playlists} | users.playlists

Laravel - Paginate and get()

瘦欲@ 提交于 2019-12-18 19:24:02
问题 With the code below, what I wanted was paginate the query I created. But, when I try to add paginate after get, it throws an error. I wanted to remain get since I want to limit to columns that was set on $fields. What would should be the better idea to paginate this thing? or what's a good substitute for get and limit the columns? What I tried: ->get($this->fields)->paginate($this->limit) Part of my controller: class PhonesController extends BaseController { protected $limit = 5; protected

Laravel - Paginate and get()

安稳与你 提交于 2019-12-18 19:23:08
问题 With the code below, what I wanted was paginate the query I created. But, when I try to add paginate after get, it throws an error. I wanted to remain get since I want to limit to columns that was set on $fields. What would should be the better idea to paginate this thing? or what's a good substitute for get and limit the columns? What I tried: ->get($this->fields)->paginate($this->limit) Part of my controller: class PhonesController extends BaseController { protected $limit = 5; protected

Laravel 4: reading cookies set by javascript

我的梦境 提交于 2019-12-18 19:12:27
问题 If I set a cookie with javascript, how would I read it using Laravel 4? The reason I'm asking is that the docs say: All cookies created by the Laravel framework are encrypted and signed with an authentication code, meaning they will be considered invalid if they have been changed by the client. 回答1: Just use the native PHP command to retrieve cookies: $_COOKIE['cookie']) Or perhaps you can set the cookie via an AJAX command (rather than JS doing it itself) - and have Laravel set the cookie