laravel-4

Laravel 4 Model Events don't work with PHPUnit

核能气质少年 提交于 2020-01-13 08:58:08
问题 I build a model side validation in Laravel 4 with the creating Model Event : class User extends Eloquent { public function isValid() { return Validator::make($this->toArray(), array('name' => 'required'))->passes(); } public static function boot() { parent::boot(); static::creating(function($user) { echo "Hello"; if (!$user->isValid()) return false; }); } } It works well but I have issues with PHPUnit. The two following tests are exactly the same but juste the first one pass : class UserTest

Route to controller in subfolder not working in Laravel 4

我是研究僧i 提交于 2020-01-13 08:49:26
问题 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'); 回答1: 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:

How to count eloquent relationship without the N+1 issue and loading the entire model?

回眸只為那壹抹淺笑 提交于 2020-01-13 07:16:15
问题 I am showing a list of categories, and the article count within each category. I get the expected result, but I am having the N+1 problem. My CategoriesController index function: public function index() { return View::make('categories.index', [ 'articleCategories' => Category::where('type', 'articles')->orderBy('name')->get(), ]); } The Category model has many relationship to articles: public function articles() { return $this->hasMany('Article'); } My categories.index view: @foreach(

Conversation, Many-to-Many relationship

岁酱吖の 提交于 2020-01-13 03:35:25
问题 I am developing an application where I need users to interact with each other using a chat-like system. To this purpose, I want to create a Conversation model. As far as I've been able to read, I am going to use a Many-to-Many relationship. Having the following models: Conversation , User and Message , I imagined the following tables: conversations: id | user1_id | user2_id - I am not sure if Laravel would understand the user IDs being numbered messages: id | message | conversation_id | user

Override a core Laravel 4 class method

放肆的年华 提交于 2020-01-12 05:37:05
问题 Apologies if this is a dumb question as a lot of Laravel 4 is new to me. I'm trying to override a couple of the methods in the core password functionality as I want to define my own password validation rules (hardcoded into core at the time of posting), and change the method of error reporting ($errors array used on other forms, rather than than session-based). So my approach was to create a new class in /app/lib/MyProject/User called Password.php that looks like this: <?php namespace

Laravel extend package class

半城伤御伤魂 提交于 2020-01-12 04:05:12
问题 I added a cart package to my Laravel install, but I need to add a method to the class. If I modify the class directly, will my changes be overwritten when I update to a newer version? If so, what's the best method for modifying a package without breaking future updates? Thanks for the help! -JB 回答1: I don't know if there is any general process to extend Laravel 5.0 package from vendor directory and I am sure this may be different for different packages. But saying that, I faced the same issue

Laravel extend package class

主宰稳场 提交于 2020-01-12 04:04:43
问题 I added a cart package to my Laravel install, but I need to add a method to the class. If I modify the class directly, will my changes be overwritten when I update to a newer version? If so, what's the best method for modifying a package without breaking future updates? Thanks for the help! -JB 回答1: I don't know if there is any general process to extend Laravel 5.0 package from vendor directory and I am sure this may be different for different packages. But saying that, I faced the same issue

How to find #hashtags in strings using Laravel 4.1?

江枫思渺然 提交于 2020-01-11 12:55:10
问题 I am currently trying to filter through an Input string to find the single hashtags that a user wants to be displayed with his photo. However, I am currently getting inserts in my database that are not correct. The best case scenario would be that every single hashtag is saved in a new database row with the photo id. However, I do not really know what to do to accomplish that. $hashtag = new Hashtag; $hashtag->photo_id = $photo->id; $hashtag_string = Input::get('hashtags'); $hashtag_string =

How can I get the current view name inside a master layour in Laravel 4?

本秂侑毒 提交于 2020-01-11 09:55:13
问题 in Laravel 4 I have a master blade layout and I want to add a class to the html element like 'tpl-home', but I need to know which is the current view name called with View::make. <!doctype html> <html lang="es" class="tpl-{{Str::slug($currentViewName)}}"> Does Laravel provide any function for retrieving this? Thanks 回答1: Inside your filters file place: View::composer('*', function($view){ View::share('view_name', $view->getName()); }); Then in your master blade layout you can access it as

How can I get the current view name inside a master layour in Laravel 4?

╄→尐↘猪︶ㄣ 提交于 2020-01-11 09:55:11
问题 in Laravel 4 I have a master blade layout and I want to add a class to the html element like 'tpl-home', but I need to know which is the current view name called with View::make. <!doctype html> <html lang="es" class="tpl-{{Str::slug($currentViewName)}}"> Does Laravel provide any function for retrieving this? Thanks 回答1: Inside your filters file place: View::composer('*', function($view){ View::share('view_name', $view->getName()); }); Then in your master blade layout you can access it as