laravel-4

How to create rotating log file with Laravel and Monlog

北城以北 提交于 2019-12-12 18:01:37
问题 I'm trying to create my own rotating log file in Laravel using Monolog, however, the file rotation is not working and I don't know why. I've created an artisan command that runs once per day, and keeps a log of it's activity. I want old versions of this file to be deleted after 2 days. In other words only the log of today's run, as well as yesterday's run should exist. At the beginning of my artisan command, I have the following code: $log = new Logger('MyCustomLog'); $log->pushHandler(new

Laravel throw Error from Model if the Condition Fails

吃可爱长大的小学妹 提交于 2019-12-12 14:40:16
问题 I am doing all the validations in Model My Rule is public static $rules = array( 'VehicleNumber' => 'required|unique:vehicle', 'NumberSeats' => 'required', 'VehicleType' => 'required', 'MaximumAllowed' => 'numeric|max:3', 'VehicleCode' => 'required|unique:vehicle'); } But for changing the file name and checking its size i am handling in a SetFooAttribute public function setInsurancePhotoAttribute($InsurancePhoto) { if($InsurancePhoto && Input::file('InsurancePhoto')->getSize() < '1000') {

Eloquent Eager Loading Constraint Limit

≡放荡痞女 提交于 2019-12-12 14:13:06
问题 I have a Post and Comment model. Post has a hasMany relationship to Comment. Comment has a belongsTo relationship to Post. I want to eager load posts with their comments, but I want to limit to only get 3 comments per posts. How can I do this by Eloquent? Post::with(array('comments' => function($query) { $query->take(3); }))->take(10)->get(); But this constraint will only load 3 comments for all the 10 posts instead of 3 comments per post. If this is not yet possible via Eloquent, is there

Laravel parent/children relationship on it's own model

五迷三道 提交于 2019-12-12 13:33:47
问题 I want to get all the vouchers that have at least one child, a voucher can have multiple voucher children, but any voucher can only have one parent. I set it up with the following models and calls, and the query it generates is as desired, until this part: 'vouchers'.'parent_id' = 'vouchers'.'id' Wanted functionality: $vouchers = Voucher::has('children')->get(); or $vouchers = Voucher::has('parent')->get(); Resulted Query select * from `vouchers` where `vouchers`.`deleted_at` is null and

Laravel and google maps : foreach latitude/longitude show marker or map

与世无争的帅哥 提交于 2019-12-12 13:06:30
问题 I have a table locations with a latitude and longitude field. For each location I want a new map (or better a new marker) that uses the latitude and longitude from the table locations to display a city on the map. index action of controller : public function index() { $locations = Location::all(); $locations->location_latitude = Input::get('location_latitude'); $locations->location_longitude = Input::get('location_longitude'); return View::make('forecasts.index') ->with('locations',

url::previous issue in laravel

徘徊边缘 提交于 2019-12-12 12:32:32
问题 I have a main list view page and a product page and an items page I have used the URL::previous() in a a href="" tag <a class="btn" title="Back" alt="Back" href="{{URL::previous()}}">Back</a> In my product page and in items page When I go to products page through list view page and press the back button it goes to the pagged url of the list view page and when I press back button in items page it goes to the product page But if I press the back button now it again goes to the items page

Laravel 4 : How to get selected/specific columns in a many to many relationship?

家住魔仙堡 提交于 2019-12-12 12:31:14
问题 I want to get all users that is related to a certain conversation. The pivot table has user_id and conversation_id columns. user_id and conversation_id references the id column on user and conversations table respectively. So I did : Conversations::find($conv_id)->users() This is ok but it returns all the details of the related user. Based on the code above, how do I return only certain columns of the user such as id and name ? P.s. Additionally, I know I can do this by creating a modal for

Laravel eloquent model - model extends model

混江龙づ霸主 提交于 2019-12-12 12:29:41
问题 is it possible to extend a laravel 4 eloquent model with another model, let's say i have a user model extending the eloquent class and additionally there is a second class, a administrator class extending the user class? If i just linked the administrator class to the user i'd have to access the administrators attributes by first getting the administrator attribute of the user and then getting the admins attributes. EDIT: Let's say I have the Administrator not extending the User. I'd have to

How to add a tag (span, small) to Laravel Form::label?

南笙酒味 提交于 2019-12-12 12:27:23
问题 In Laravel 4.1, I want to echo: <label for="name">Name <small>required</small></label> This doesn't work: {{ Form::label('name','Name <small>required</small>') }} are automatically converted to code text… Is there a way or do I have to skip Form::label and do it manually? 回答1: If you want to use a Html tag inside another by Laravel one you should use HTML::decode. Correct code : {{ HTML::decode(Form::label('name','Name <small>required</small>')) }} 来源: https://stackoverflow.com/questions

Laravel 4.2, Artisan::call() ignoring --env option

眉间皱痕 提交于 2019-12-12 12:10:08
问题 I'm building an application that needs to create a new database, perform migrations and seed db data via a web page. I'm trying to achieve this with the following code in Laravel 4.2. Note, this is within a controller I've setup. Artisan::call("migrate", array( "--env" => "production" )); No matter what environment I pass with the "--env" option, the environment that the migration is run on is the current environment that the site is currently running on. Ie. If I'm running on my local