laravel-4

Laravel unit testing of controllers

♀尐吖头ヾ 提交于 2019-12-09 04:39:28
问题 I am trying to start a new Laravel app following TDD My first step is to check that the /login controller is called on the home url. Despite following several tutorials I can't get the test to work and I can't see what I'm doing wrong at all. My set up is: composer to install laravel composer to install phpunit here is my route: <?php Route::get('/login', 'AuthenticationController@login'); my controller: <?php class AuthenticationController extends BaseController { public function login () {

Laravel - Convert database integer to an associated string

﹥>﹥吖頭↗ 提交于 2019-12-09 04:30:32
I have my users table with a column named status . In this column I just store a number, based off their status, 1 - admin, 2 - owner, etc. I know that I can display these values with {{ users->status }} , but only shows the stored number. How can I show the actual name instead of the stored number? Use Eloquent Accessors & Mutators . Define an array of statuses and use the status number from your database as a key to change the value in the model so that in the view {{ $users->status }} equals admin class User extends Eloquent { protected $statuses = array( '1' => 'admin', '2' => 'owner' );

Laravel 4: Reference controller object inside filter

北城以北 提交于 2019-12-09 03:30:58
问题 I have a controller in Laravel 4, with a custom variable declared within it. class SampleController extends BaseController{ public $customVariable; } Two questions: Is there any way I can call within a route filter: The controller object where the filter is running at. The custom variable from that specific controller ($customVariable). Thanks in advance! 回答1: as per this post: http://forums.laravel.io/viewtopic.php?pid=47380#p47380 You can only pass parameters to filters as strings. //routes

laravel blade, how to append to a section

妖精的绣舞 提交于 2019-12-09 00:25:38
问题 If you look to laravel official documentation http://laravel.com/docs/4.2/templates It says that giving this layout: <!-- Stored in app/views/layouts/master.blade.php --> <html> <body> @section('sidebar') This is the master sidebar. @show <div class="container"> @yield('content') </div> </body> </html> Extended by this view @extends('layouts.master') @section('sidebar') <p>This is appended to the master sidebar.</p> @stop @section('content') <p>This is my body content.</p> @stop Will append

Laravel: One to Many to Many, retrieve distinct() values

ぐ巨炮叔叔 提交于 2019-12-08 23:48:56
问题 Laravel 4 Project, using Eloquent ORM. I have three tables: customers, orders and products (+ 1 pivot table order_product). Customers are linked one-to-many to Orders. Orders are linked many-to-many to Products. Customers 1-->N Orders N<-->N Products I would like to have a method on Customer model that retrieves a list of products that customer is buying. To better understand this, assume products are consumable. For example Customer #1 can place: Order #1 for Products A, B and C; Order #2

how to enable error reporting in laravel 4.2 for debugging

陌路散爱 提交于 2019-12-08 20:48:21
问题 I just have installed new laravel 4.2 using composer . I make syntax mistake deliberately on my router.php to see if an appropriate exception is thrown by the application on my browser screen, but instead a got this Whoops, looks like something went wrong . i have checked the app/config.ph p file and changed "debug" = false to "debug" = true and it is not worked for me. Still I am getting the same message. does any body know how to configure laravel 4 to display error message on my screen?

Laravel 4, how to apply filters on Route::controller()

▼魔方 西西 提交于 2019-12-08 19:47:59
问题 I know i can do this Route::get('foo/bar', array('before' => 'filter', 'uses' => 'Controller@bar')); to apply routes some filter. I am aware of Route::group() method too. Anyway, if i want to define a controller in this way Route::controller('foo/{id}/bar', 'Controller'); i can not pass an array as the 2nd argument. The question: how to apply filters to the following route? Route::controller('foo/{id}/bar', 'Controller'); === EDIT I want to code this in my route.php, not inside a controller

Laravel Blade Templates Section Repeated / cache error

亡梦爱人 提交于 2019-12-08 19:42:15
问题 I am looking to Bootstrap my site and as such, have put common twitter bootstrap components into blade templates. sidebar.blade.php @include('panel1') @include('panel2') panelTemplate.blade.php <div class="panel panel-primary"> <div class="panel-heading"> <div class="panel-title"> @yield('title') </div> </div> <div class="panel-body"> @yield('body') </div> <div class="panel-footer"> @yield('footer') </div> </div> This way, every time I wish to use a panel, then I can use @extends(

laravel redirect to a new tab

旧街凉风 提交于 2019-12-08 19:08:03
问题 I need to open a new URL after a post request. I have done this at the end of my controller. Redirect::away($url) The above calls works perfect, however, I want to open the URL in a new tab . I tried to, away, and intended methods that are there in the laravel doc. None work as intended. 回答1: Redirect::away() or Redirect:to() both are server side commands and all they do is to redirect to a url with a slight difference as mentioned in this thread As, both are server side commands they cannot

Can the with function be used with a GroupBy clause in Laravel Eloquent?

独自空忆成欢 提交于 2019-12-08 18:03:01
问题 Can the with function be used with a GroupBy clause in Laravel Eloquent? Does it serve any purpose if I have specific items to select using the Select Clause? Following is the query that I currently have Order::with('Campaign') ->where('isapproved','=','Y') ->groupBy('campaign_id') ->orderBy(DB::raw('COUNT(id)','desc')) ->get(array(DB::raw('COUNT(id) as totalsales'))); The order table has a column name campaign_id which belongsTo the table named campaigns . I would like to get the total count