laravel-4

Laravel 4: Confused about how to use App::make()

时光总嘲笑我的痴心妄想 提交于 2019-12-04 09:44:25
问题 I am trying to follow the repository pattern outlined in this article http://code.tutsplus.com/tutorials/the-repository-design-pattern--net-35804#highlighter_174798 And I am trying to instantiate a class in Laravel using App::make() (Which I am guessing is Laravel's factory pattern?) and I am trying to parse arguments to my class but I can't work out how to do it. Code: namespace My; class NewClass { function __construct($id, $title) { $this->id = $id; $this->title = $title; } } $classArgs =

Laravel Validation: check why validator failed

こ雲淡風輕ζ 提交于 2019-12-04 09:38:37
问题 If there a way to check whether or not the validator failed specifically because of the unique rule? $rules = array( 'email_address' => 'required|email|unique:users,email', 'postal_code' => 'required|alpha_num', ); $messages = array( 'required' => 'The :attribute field is required', 'email' => 'The :attribute field is required', 'alpha_num' => 'The :attribute field must only be letters and numbers (no spaces)' ); $validator = Validator::make(Input::all(), $rules, $messages); if ($validator-

Laravel psr-4 not autoloading

廉价感情. 提交于 2019-12-04 09:31:59
I have a Laravel project that works fine locally (Mavericks), but classes under psr-4 aren't loading on our stage server (CentOS). I'm getting a Reflection "class not found" error every time I try composer update, or run an artisan command. All my app-specific classes are stored in my Laravel project under app/heatherland, eg: app/heatherland/import/ImportJob.php (file contains HeatherLand\Import\ImportJob) My composer.json contains this entry: "autoload": { "classmap": [ "app/commands", ... "app/database/seeds", ], "psr-4": { "HeatherLand\\": "app/heatherland" } }, Locally, the psr-4 classes

Conversation, Many-to-Many relationship

你。 提交于 2019-12-04 09:16:00
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_id Would this be the right way to do it? And will it work with the user1_id and user2_id tables? I

Laravel whereIn OR whereIn

让人想犯罪 __ 提交于 2019-12-04 08:55:06
问题 I'm making a products search by filters: My code: ->where(function($query) use($filter) { if(!empty($filter)){ foreach ($filter as $key => $value) { $f = explode(",", $value); $query-> whereIn('products.value', $f); } } }) Query: and (products.value in (Bomann, PHILIPS) and products.value in (red,white)) But I need: and (products.value in (Bomann, PHILIPS) OR products.value in (red,white)) Is there something similar in Laravel: orWhereIn 回答1: You could have searched just for whereIn function

Laravel eloquent ORM group where

邮差的信 提交于 2019-12-04 08:49:50
问题 How do I convert the following query to Laravel 4 eloquent ORM? select * from table where ((starttime <= ? and endtime >= ?) or (starttime <= ? and endtime >= ?) or (starttime >= ? and endtime <= ?)) 回答1: Like this: <?php $results = DB::table('table') ->where(function($query) use ($starttime,$endtime){ $query->where('starttime', '<=', $starttime); $query->where('endtime', '>=', $endtime); }) ->orWhere(function($query) use ($otherStarttime,$otherEndtime){ $query->where('starttime', '<=',

Browser Cache issues in Laravel 4 Application

*爱你&永不变心* 提交于 2019-12-04 08:39:30
I'm having an issue with the browser cache interfering with my Laravel application. If the browser cache is disabled, everything works fine. However, if enabled, and the same link is clicked repeatedly, the Laravel method to create the view or collect data is not even executed. The implications are manifold. For instance, a form to edit a resource or a grid which displays data (loaded form the server using ajax), do not show the current values until the browser is reloaded. I've put a line in some of my methods which logs the current timestamp to prove this. public function index() { Log::info

Laravel 4 generate not working

本秂侑毒 提交于 2019-12-04 08:37:04
问题 I am new to frameworks please help me out with this. I am trying to create a file in controller using generate. The following is the command php artisan generate:controller features it gives me the error [InvalidArgumentException] There are no command defined in the "generate" namespace 回答1: The generate command is from the JeffreyWay/Laravel-4-Generators package, to install it you have to execute composer require way/generators 2.* And then add this line to your app/config/app.php in the

Can Laravel 4 log to a MySQL database?

蓝咒 提交于 2019-12-04 08:36:30
问题 If so how can it be done? By default L4 writes to a text file. I notice that Monolog can Log to Database on its github page. 回答1: Yep, You could create a listener to log everything in the routes.php Event::listen('laravel.log', function($type,$message) { $log = new Log(); $log->message = $message; $log->type = $type; $log->update; }); Or alternatively if you wanted to only log errors 400 and 500 Larvavel there is a Log event in the Routes.php file which listens to errors 404 and 500, you can

Laravel Eloquent - Using pivot table's id as a foreign key in another table

血红的双手。 提交于 2019-12-04 08:33:01
问题 I need to use pivot table's id as a foreign key in another table. for example i have following tables: users: id, username, ... places: id, placename, lat, lng, ... place_user: id, user_id, place_id routes: place_user_id, lat, lng, inserted_at. so when user says I am going to that place, I have a new entry in place_user table and start to log the route he takes to get there. So for each place_user entry i have many entries in routes table. what is the correct way of doing this kind of