milroy

milroy

Member Since 4 Years Ago

Colombo, Sri Lanka

Founder & Software Engineer at Olionsoft

Experience Points 5,820
Experience Level 2

4,180 experience to go until the next level!

In case you were wondering, you earn Laracasts experience when you:

  • Complete a lesson — 100pts
  • Create a forum thread — 50pts
  • Reply to a thread — 10pts
  • Leave a reply that is liked — 50pts
  • Receive a "Best Reply" award — 500pts
Lessons Completed 2
Lessons
Completed
Best Reply Awards 5
Best Reply
Awards
  • start-engines Created with Sketch.

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • first-thousand Created with Sketch.

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • 1-year Created with Sketch.

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • 2-years Created with Sketch.

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • 3-years Created with Sketch.

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • 4-years Created with Sketch.

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • 5-years Created with Sketch.

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • school-session Created with Sketch.

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • welcome-newcomer Created with Sketch.

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • full-time-student Created with Sketch.

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • pay-it-forward Created with Sketch.

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • subscriber-token Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer-token Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • lara-evanghelist Created with Sketch.

    Laracasts Evangelist

    Earned if you share a link to Laracasts on social media. Please email [email protected] with your username and post URL to be awarded this badge.

  • chatty-cathy Created with Sketch.

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • lara-veteran Created with Sketch.

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • 10k-strong Created with Sketch.

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • lara-master Created with Sketch.

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • laracasts-tutor Created with Sketch.

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • laracasts-sensei Created with Sketch.

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • top-50 Created with Sketch.

    Top 50

    Earned once your experience points ranks in the top 50 of all Laracasts users.

16 Apr
3 years ago

milroy started a new conversation What Is The Correct Way To Write The Gulp File

''' var elixir = require('laravel-elixir');

elixir(function(mix) {

mix.copy('./bower_components/bootstrap/fonts', 'public/fonts'); mix.copy('./bower_components/font-awesome/fonts', 'public/fonts');

mix.sass([ "site.scss" ], 'public/css/site.css')

.styles([ "./bower_components/bootstrap/dist/css/bootstrap.css", "./bower_components/font-awesome/css/font-awesome.css", "./bower_components/Selecter/jquery.fs.selecter.min.css", "./bower_components/baguettebox.js/build/css/baguetteBox.css", "./public/css/site.css" ], 'public/css/all.css')

.scripts([ "./resources/assets/scripts/vendor/modernizr.js" ], 'public/js/modernizr.js')

.scripts([ "./bower_components/html5shiv/dist/html5shiv.js", "./bower_components/respond/dest/respond.src.js" ], 'public/js/html5shiv.and.respond.js')

.scripts([ "./bower_components/jquery/dist/jquery.js", "./bower_components/bootstrap/dist/js/bootstrap.js", "./bower_components/headhesive/dist/headhesive.js", "./bower_components/Selecter/jquery.fs.selecter.js", "./bower_components/baguettebox.js/build/js/baguetteBox.js" ], 'public/js/all.js')

.version(["css/all.css", "js/all.js", "js/modernizr.js", "js/html5shiv.and.respond.js"]);

});

elixir(function(mix) { mix.browserSync({ proxy: 'olionsoft.dev' }); });

'''

I'm new to node world. I would like to know what is the correct way to write the gulp file. What is the use of elixir / mix and chaining.

29 Jan
3 years ago

milroy started a new conversation Lack Of Memory And Not Having Swap Configured

I just started working with Forge + Envoyer + DigitalOcian. I'm getting this error on envoyer while I'm trying to deploy one of my old Larave 4.2 projects.

Using global Composer installation.
Loading composer repositories with package information
Installing dependencies (including require-dev)
  - Installing symfony/translation (v2.5.12)
    Loading from cache
The following exception is caused by a lack of memory and not having swap configured
Check https://getcomposer.org/doc/articles/troubleshooting.md#proc-open-fork-failed-errors for details

                                                     
  [ErrorException]                                   
  proc_open(): fork failed - Cannot allocate memory  

How can I fix this ..?

22 Nov
3 years ago

milroy left a reply on Watch An Extension

@JeffreyWay could you please look in to this? I'm using elixir in a Vue application. Tnx.

21 Nov
3 years ago

milroy started a new conversation Watch An Extension

// elixir-extensions.js

var fs          = require('fs');
var gulp        = require('gulp');
var handlebars  = require('gulp-compile-handlebars');

var Elixir = require('laravel-elixir');

var $ = Elixir.Plugins;

var manifest    = JSON.parse(fs.readFileSync('./public/build/rev-manifest.json', 'utf8'));

var handlebarOpts = {
    helpers: {
        assetPath: function (path, context) {
            return ['build', context.data.root[path]].join('/');
        }
    }
};

Elixir.extend('render', function() {
    new Elixir.Task('render', function() {
        return gulp
            .src('./resources/assets/hbs/index.hbs')
            .pipe(handlebars(manifest, handlebarOpts))
            .pipe($.rename('index.html'))
            .pipe(gulp.dest('public'));
    })
     .watch('./resources/**/*.+(js|coffee|css|less|sass|scss)')
});

// gulpfile.js

require('./elixir-extensions')

elixir(function(mix) {
    mix.render();
});

watch is not working. I want to run this task if any of the js|coffee|css|less|sass|scss file chainged in resources/**

milroy started a new conversation Elixir With Vue App

I'm just starting Vuejs application. Planning to use laravel-elixir. But I couldn't find a way to get the version file path from rev-manifest.json. What is the best way to do it?

04 Aug
3 years ago

milroy started a new conversation Testing Every Possibility..?

Lets assume that I need to write tests for my RESTful API create post request POST request to api.myapp.com/v1/posts

  • title, body, auther_id are required fields
  • type_id NOT required

when I'm testing validations is it a must to test every possibility e.g.

  • when title is empty and other fields are valid
  • when type_id is empty and other fields are valid
  • when type_id is not in range and other fields are valid
  • and ...
03 Aug
3 years ago

milroy left a reply on Check If Date String Is Equal To The Las 5 Days

@socieboy

$dt         = Carbon::parse('2015-08-03 11:52:52');
$now    = Carbon::now();
$from   = Carbon::now()->subDays(29);

if($dt->between($from, $now)))
{
    // true
}

milroy left a reply on How To Find Employee Who Is Absent Continuously More Than 10 Days?

@mshs07 I think this can't be done from a direct query. You will have to perform some operations.

  • retrieve all att records
  • compare date diff while looping through
  • count up if diff > 1 may be

but this is going to fail soon, if you are implementing this to mark attendance of company,organization,etc.. because you have to consider about holidays.

a solution would be

  • predefined holidays
  • schedule a task to run at a given time to mark absence
31 Jul
3 years ago

milroy left a reply on Elixir Merge Less & Css Files

@hostianer yes mix.styles searches in "resources/assets/css/"

but when

mix.less([
        'pages.less','resources/assets/css/pages.css'
    ]);

it should create the file in "resources/assets/css/"

milroy left a reply on Elixir Merge Less & Css Files

mix.less([
        'pages.less','public/css/style.css'
    ]);

milroy left a reply on Route And Pagination Problems

@mardev It will work if you configure a virtual host or when you host your app.

milroy left a reply on Elixir Merge Less & Css Files

@hostianer small chainge in the path would do

mix.less([
        'pages.less','public/css/style.css'
    ]);

mix.styles([
        'plugins/pace/pace-theme-flash.css',
        'plugins/boostrapv3/css/bootstrap.min.css',
        'plugins/font-awesome/css/font-awesome.css',
        'plugins/jquery-scrollbar/jquery.scrollbar.css',
        'plugins/bootstrap-select2/select2.css',
        'plugins/switchery/css/switchery.min.css',
        'style.css'
    ]);

milroy left a reply on Elixir Merge Less & Css Files

@hostianer

mix.less([
        'pages.less','resources/assets/css/style.css'
    ]);

mix.styles([
        'plugins/pace/pace-theme-flash.css',
        'plugins/boostrapv3/css/bootstrap.min.css',
        'plugins/font-awesome/css/font-awesome.css',
        'plugins/jquery-scrollbar/jquery.scrollbar.css',
        'plugins/bootstrap-select2/select2.css',
        'plugins/switchery/css/switchery.min.css',
    'resources/assets/css/style.css'
    ]);

milroy left a reply on Polymorphic Relations

@hardsshah as per your table structure it should be possible to simple implement an one to many relationship in your model.

public function users()
{
    return $this->hasMany('App\Comment');
}

And also I would like to suggest you to rename morph columns in you table as "resourceable_type" | "resourceable_id" as the morph relationship doesn't return User related models, so I think it makes more sense.

By assuming

  • table name : roles
  • column names "resourceable_type" | "resourceable_id"
  • model would be : Role
class Role extends Model
{
    public function resourceable()
    {
        return $this->morphTo();
    }
}

class Post extends Model
{
    public function roles()
    {
        return $this->morphMany('App\Role', 'resourceable');
    }
}    

class Document extends Model
{
    public function roles()
    {
        return $this->morphMany('App\Role', 'resourceable');
    }
}    

so you can query

Post::find(1)->roles()->first()->users();
16 Jul
4 years ago

milroy left a reply on Eloquent Relationship

@cssraja please update your models

class Area extends Model
{
    public function state()
    {
        return $this->belongsTo('App\State');
    }
}

class State extends Model
{
    public function areas()
    {
        return $this->hasMany('App\Area');
    }
}

and you can query

$area = Area::with('state')->where('name', 'xxx')->first();  
$state_name = $area->state->name;
15 Jul
4 years ago

milroy left a reply on Deleting An Entity Does Not Delete Its Relations

@pr4xx would you like to share any disadvantage of using cascade mehtod?

milroy left a reply on Deleting An Entity Does Not Delete Its Relations

seems like you have missed ->onDelete('cascade') in your migration

// network_block migration 
$table->integer('vpn_id')->unsigned()->index();
$table->foreign('vpn_id')->references('id')->on('vpns')->onDelete('cascade');

// network migration 
$table->integer('network_block _id')->unsigned()->index();
$table->foreign('network_block ')->references('id')->on('network_blocks ')->onDelete('cascade');
14 Jul
4 years ago

milroy left a reply on Flash Message Exists In Other Requests

@dixitchopra can you share your code here?

milroy left a reply on SQLSTATE[HY000] [2002] No Such File Or Directory

@peter add port to mysql configuration array

'mysql' => [
      'driver'    => 'mysql',
      'host'      => env('DB_HOST', '127.0.0.1'),
      'port'      => '8889',
      'database'  => env('DB_DATABASE', 'db_name'),
      'username'  => env('DB_USERNAME', 'root'),
      'password'  => env('DB_PASSWORD', 'root'),
      'charset'   => 'utf8',
      'collation' => 'utf8_unicode_ci',
      'prefix'    => '',
      'strict'    => false,
],

NOTE: better to set it in you .env

12 Jul
4 years ago

milroy left a reply on Multiple Relationships, Is There An Elegant Way To Pass This To The View?

you can nested eager loading and pass it to the view

$orders = User::with('orders.products')->find($user_id);

so you can loop through

milroy left a reply on Custom Validation For Password Reset Laravel 5

oopz Sorry I miss read your ques. It's not good to edit the framework directly. let me check

milroy left a reply on Custom Validation For Password Reset Laravel 5

'password' => 'required|confirmed|min:8',

milroy left a reply on Using Another Table In A Many To Many Relationship Setup

@pmall I hope you should maintain another Station Song pivot table with an extra timestamp column "played_at" may be. so you can directly query through ->wherePivot()

milroy left a reply on Use One Table To Store All Comments

comments table should have a Polymorphic Relations to Questions and Answers table

commentable_type,commentable_id

if you want to comment on a comment should have a self relationship

milroy left a reply on Relationships

I hope you have implemented orders() method correctly according to your relationship. if so eager load

$dealer = DealersModel::with('orders')->where('user_id', $user->id)->get(); // get dealer
$orders = $dealer->orders->get()->toArray();
02 Jul
4 years ago

milroy left a reply on Laravel 5 Authentication

@WillyCornelissen make sure you set character encoding to utf-8 in php file. if not it will show you some %^$^&%&s76s :)

milroy left a reply on Extending Templates

yes

master.blade.php

<body>
@yield('content')
@yield('footer')
</body>

site.blade.php

@extends('masters')

@section('content')
    @yield('workspace')
@stop

@section('footer')
    <footer>
    </footer>
@stop

about.blade.php

@extends('site')

@section('workspace')
    <h1>About Laravel</h1>
@stop

28 Jun
4 years ago

milroy left a reply on A Little Code Suggestion

@giacomoferrari

public function inviteInGroup($id,AddUserToGroupRequest $request)
{
    $email = $request->get('email');
    $user = $this->user_repo->findByEmail($email);

    if($user)
        return $this->user_repo->addToGroup($id);

    return Response::json(array(
        'message' => 'User not found!'
    ), 404);
}
  1. Validate inputs by injecting a form request "AddUserToGroupRequest"
  2. Move all DB operations to a repository. "user_repo"
  3. Remove all unnecessary else statements

Happy Coding!!

27 Jun
4 years ago

milroy left a reply on Handling Foreign Checks In Laravel 5 Migrations

@Akcium small chaing would do ->index()

$table->integer('user_id')->unsigned()->index();
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
17 Jun
4 years ago

milroy left a reply on How To Pass Data To View With Condition Wether Data Is Defined Or Not

@vicnumb before you code

$userdata->datavalue

you will have to make sure $userdata is not null or what you expected to be. so what I suggest you is to debug or dump variable before you use it to get a clear idea.

dd($userdata);
return view('admin.templates')
      ->with('selecteddata', $userdata->datavalue);
07 Jun
4 years ago

milroy started a new conversation Where Clause In Nested Eager Loading

public function getJobWithDocumentsByID($id)
 {
        return Job::with(['documents' => function($query){
             $query->orderBy('job_doc_type_id');
             $query->orderBy('created_at','desc');
         }])
         ->find($id);
}

I need to eager load

documents.auther
05 Jun
4 years ago

milroy started a new conversation How To Implement Composite Primary Key

Batches and Subjects has many to many relationship. Exams should have a composite primary key

batch_id,subject_id,...

How to implement this.?

milroy left a reply on Call To A Member Function GetClientOriginalExtension() On A Non-object

@smagafu

*01. make sure form allows file upload "files=true"

{!! Form::open(['route' => ['vs.store',$user->id],'files' => true]) !!}

*02. validate file filed in you request->rules()

return [
    'myfile' => 'required'
];

*03. Then try

$file = $request->file('myfile');
$ext = $file->getClientOriginalExtension();

assuming you file input field name is "myfile"

04 Jun
4 years ago

milroy left a reply on Protecting Route For Specific User

Best place to do your authorization is in request -> authorize

php artisan make:request PostEditRequest

command will generate App/Http/Requests/PostEditRequest.php. You have to implement all you authorize function. You can access request params in authorize function simple as

$this->get('id')
29 May
4 years ago

milroy left a reply on 301 Redirect To Non Index.php Url

@bashy it happens on justhost shared host :). I write a partial solution, but still I'm looking for a better solution [301] redirect.

<link rel="canonical" href="{{ str_replace('/index.php','',Request::url()) }}" />
28 May
4 years ago

milroy left a reply on 301 Redirect To Non Index.php Url

@bashy I have updated my .htaccess files as follows

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>
    
    RewriteEngine On
    RewriteRule ^index.php/(.*)$ $1 [R=301,L]
    
    # Redirect www to non-www
    RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
    RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

    # Redirect Trailing Slashes...
    RewriteRule ^(.*)/$ /$1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

now when I visit

abc.com/index.php/contact
redirects to
abc.com/home5/www/public_html/mysite/public/contact

milroy left a reply on 301 Redirect To Non Index.php Url

@bashy I have no idea about .htaccess syntax. I just added few lines to laravel default .htaccess to redirect all urls from www to non-www url, and it works.

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>
    
    RewriteEngine On
    
    # Redirect www to non-www
    RewriteBase /
    RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
    RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

    # Redirect Trailing Slashes...
    RewriteRule ^(.*)/$ /$1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

is it possible to modify the above code or write a new to full fill

  • Redirect www to non-www
  • Redirect Trailing Slashes
  • Handle Front Controller
  • REDIRECT any url which contains /index.php by repacing /index.php with "" (empty)

milroy left a reply on 301 Redirect To Non Index.php Url

Tnx all once again @mstnorris @bashy @sitesense really appreciate your support.

It looks like a common issue in all the websites built with laravel. even in

You can visit the same page from two urls. Which is an extra work for SEO guys and effects to the search engine ranking. I was trying to fix this issue via public/.htaccess . What is the best solution for this.

Really appreciate if you can look in to this @JeffreyWay @TaylorOtwell and make it happen in the core.

e.g.

http://laravel.com/index.php/docs/5.0  =  http://laravel.com/docs/5.0
https://laracasts.com/index.php/series  =  https://laracasts.com/series
https://oneplus.net/index.php/one  =  https://oneplus.net/one

query this on google "site:laracasts.com/index.php" so you can see already indexed duplicate content.

milroy left a reply on 301 Redirect To Non Index.php Url

@bashy it redirects all requests to base url.

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>
    
    RewriteEngine On
    
    # Redirect www to non-www
    RewriteBase /
    RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
    RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

    # Redirect Trailing Slashes...
    RewriteRule ^(.*)/$ /$1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
    
    RewriteRule ^index.php/?(.*)$ $1 [R=301,L]
</IfModule>

milroy left a reply on 301 Redirect To Non Index.php Url

tnx @bashy. I have no issues with redirection www to non-www only issue is I want to remove /index.php and [301] redirect to any url.

e.g.
abc.com/index.php/contact  to  abc.com/contact

It's a requirement from our SEO team.

@JeffreyWay any solution for this found lots of google indexed pages through /index.php site:laracasts.com/index.php

milroy left a reply on 301 Redirect To Non Index.php Url

this doesn't work :(

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>
    
    Options +FollowSymLinks -MultiViews

    RewriteEngine On
    
    # Redirect www to non-www
    RewriteBase /
    RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
    RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

    # Redirect Trailing Slashes...
    RewriteRule ^(.*)/$ /$1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
    
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s(.*)/index\.php [NC]
    RewriteRule ^ %1 [R=301,L]
</IfModule>

milroy left a reply on 301 Redirect To Non Index.php Url

Thanks @mstnorris. it's really helpful. But still there's a small issue. It redirects to the base url e.g. abc.com/index.php/contact redirects to abc.com. I need it to be redirected to abc.com/contact

milroy started a new conversation 301 Redirect To Non Index.php Url

Laravel allows to visit a page with /index.php. How to remove and [301] redirect to page without /index.php

e.g. abc.com/index.php/contact to abc.com/contact