Asst. In at UFL



10 Best Reply Awards

  • Member Since 2 Years Ago
  • 626 Lessons Completed
  • 1 Favorite

5th March, 2018

gator left a reply on Using PHP Functions In View • 7 months ago

I would just use a static function on a class - store the class in your psr-4 loaded space.

10th February, 2018

gator left a reply on Using SQL Views, Best Practices • 8 months ago

I use views for reporting all the time.

You can use

return DB::table('view name')->get();

This way, you can avoid creating trivial models.

6th February, 2018

gator left a reply on Laracasts Facebook No More? • 8 months ago

It has just been archived - it is 3 yrs old.

gator left a reply on To Display Logged In Username In Top Div. • 8 months ago

what @wilk_randall said.. If security is important to you/your application then cookies should not be used to store anything except a session ID.

2nd February, 2018

gator left a reply on How To Change Project Window Color To Match With Code Editor In PHPStorm 2017 • 8 months ago

Hmm.. looks like this project is discontinued too-

You can however, download the jar file from jetbrains repos and manually move it to: C:\Users\username.PhpStorm2017.3\config\plugins

31st January, 2018

gator left a reply on How To Change Project Window Color To Match With Code Editor In PHPStorm 2017 • 8 months ago

I use "Color Tree" plugin.. works the same.

29th January, 2018

gator left a reply on Laravel 5.4 - How To Put File In The Database Directory • 8 months ago

@wardaddy the error message still refers to your earlier code - using file_put_contents (DatabaseController line 25)

You are not yet using the code suggested by @jryd (which should work as expected).

27th January, 2018

gator left a reply on Laravel 5.5 For The Next 5 Years • 8 months ago

Of course - use the latest and greatest when you start. Upgrades depend on your business need. If you have a single project that you are entirely responsible for (much like Laracasts/Forge), then it helps to be on the bleeding edge.

Otherwise, if you have a project built using an older version/framework that works well, it makes sense to continue maintaining it until it is no longer possible to do so. Clients are least bothered about the technology behind an app. I still maintain a couple of projects written using CodeIgniter! Upgrades/rewrites are not to be taken lightly especially for a heavily used system in production.

gator left a reply on Migrate From Zend Framework To Laravel • 8 months ago

@DINESHKUMARBH "Migrating" the framework is not feasible - The two frameworks are completely different. It will essentially have to be a "rewrite"...Create a blank laravel 5.5 project, then start with the routes file/ZF bootstrap and go from there.

If you have used good programming practices and separated your ZF code into modules/classes, it will make your job a little easier.

25th January, 2018

gator left a reply on Is There Any Server That You Would Recommend To Use With Laravel For Local Development? • 8 months ago

I presume you mean on Windows?

This is the closest you can get to Laravel valet on windows :

I highly recommend it.

22nd January, 2018

gator left a reply on 301 Moved Permanently • 8 months ago

Hmm.. you seem to have followed all the instructions as described in the docs correctly (

What is the response when you uncomment dd($response) above?

If it still gives you an error, I would suggest you use your apikey and account_id, and try the call with postman (chrome extension)

gator left a reply on Dependency Injection - Getting A Handle On Drawbacks • 8 months ago

Quite the opposite.

The goal of DI is to have a "central" place where dependencies are initialized - In Laravel, this is done within Service Providers using app()->bind() OR app()->singleton() OR app()->instance() - these methods bind a string "key" to an object "instance".

if you use DI properly, you will never have lines such as

$prod = new Product($dependency1, $dependency2);

peppered throughout your application.

Instead, you will have a single service provider where you have:

$this->app->bind('product', function ($app) {
    return new Product($dependency1, $dependency2);

This binds the string "product" to the object Product. Then, you can retrieve the fully constructed product either via automatic resolution (within controllers, routes and events) by including 'product' in functions/constructors.

Alternatively, you can manually resolve it (for example in unit tests) using:

$product = $this->app->make('product');

Hope this helps.

19th January, 2018

gator left a reply on New Application With 100's Of Form Fields • 8 months ago

Your data is definitely structured. Using either KVP or JSON based representation could make data extraction needlessly painful. You may not have any relations (yet).. but obviously the data has business/decision value.

Personally, I would favor option 1.

  1. Implementation is simple and straightforward
  2. Mysql has a limit of 4000 odd columns per table.. but you could easily set up a one to one relation with another table if you approach this limit (highly unlikely)
  3. I would presume that down the line you would want to query (select and project) off of this data. This is where a relational database excels.
  4. Each piece of your data would have datatype associated with it. This would make filters easy to implement - For example when you have a field stored as a datetime, all records between a particular set of dates is trivial to select.

As far as implementation goes, you could, for example, have a "metadata" table that stores question_text, field_type, default_value, page_number (etc.). Render each form page based on the metadata table using macros for individual field types. This way, you will not need to type in html code for every single form field.

Hope this helps!

18th January, 2018

gator left a reply on Apache Can't Find Any Route That's Not The Home Page • 8 months ago

Please look at both your error and access logs for more information.

They are usually at /var/logs/apache2/access.log and /var/logs/apache2/error.log. (Confirm using httpd -V)

17th January, 2018

gator left a reply on Hopefully Simple Collection Question • 8 months ago

similar to @tykus solution.. but I think a bit more self explanatory:

$result = collect([1,2,3,4,5])->zip([6,7,8])->flatten()->filter()->all();

13th January, 2018

gator left a reply on Authentication Using Cookie Without Users Table • 9 months ago

We use Shibboleth IAM for company wide authentication. After shib auth, users are returned to the laravel app with various server variables set.. I then follow the process as outlined by @Snapey to use Laravel auth semantics... Yes, you will have 1 user row per employee who accesses your site... I don't think you can avoid this (and honestly, it falls in the bucket of items which does not warrant any action).

7th January, 2018

gator left a reply on Update Two Tables At The Same Time • 9 months ago

What is $user->id? Where is it set?

Your $user seems to be null after the find call, resulting in the error message (setting properties on a null php object)

6th January, 2018

gator left a reply on Which Session Driver Do You Recommend? • 9 months ago

For most cases, the default (FileSessionHandler) should work just fine.

Unless yours is a high traffic site, I do not see why it should be 10MB.

If you look at the source code:

The gc() routine takes care of deleting files that are older than "lifetime" specified in your config/session. I'm guessing this is not running properly.. A permissions issue perhaps? More investigation is required. Set the 'expire_on_close' option to true (in config/session) to see if it alleviates the problem.

1st January, 2018

gator left a reply on How Can I Access Environment In View? • 9 months ago

Do not put logic in the view. Instead, access the environment in the controller and pass it along to the view. More details here:

29th November, 2017

gator left a reply on Should We Concern About Choosing DMBS With Laravel? • 10 months ago

Out of the box, Laravel provides "grammars" for sqlite, mysql, postgres and sql server ( This is to iron out the differences in SQL DML operations in these databases.

Eloquent builder uses one of these grammars to build up the necessary SQL (based on your config/env selections)

So, if you are strictly using Eloquent, you do not need to concern yourself with database differences; however, if you are using highly specific raw SQL in your code, then yes, you need to be mindful of the storage engine being used, and the corresponding sql syntax.

3rd October, 2017

gator left a reply on Where Is 'php Artisan Tinker' In Lumen? • 1 year ago


composer require laravel/tinker

Then, in bootstrap/app.php



22nd September, 2017

gator left a reply on Image Intervention Usage PHP Laravel 5.4 • 1 year ago

You upload the picture using regular Laravel semantics:

Once this is done, and you have the real path of the uploaded file, you use intervention to manipulate the image...and overwrite if you wish.

14th September, 2017

gator left a reply on Return Next Item In Collection • 1 year ago

Pure php solution (definitely 'faster'.. whether it is 'easier' is subjective):

$this_id = 123;
$id_array = array('349','430','123','423','113');

$flipped = array_flip($id_array);
$next_id = $id_array[$flipped[$this_id]+1];

6th September, 2017

gator left a reply on How Do I Generate An ID With Minimum Length Of 6? • 1 year ago

A simple str_pad() call should do the trick:

$bookingID = str_pad($id,6,"0",STR_PAD_LEFT);

16th August, 2017

gator left a reply on How Do I Send Email To Multiple Recipients From A Single Email Form? • 1 year ago

'explode' event->email into an array..

$recipients = explode(',', $this->event->email);

The mail to() function can then take this array of emails and dispatch.

14th August, 2017

gator left a reply on Ads Make Site Slow • 1 year ago

@JeffreyWay , there is definitely an increase in ajax calls being made.

I can see lots of ad sites being contacted (in my status bar).. If you open your network bar, you can see... The issues seem to be caused by calls to:

8th August, 2017

gator left a reply on Factory Issue • 1 year ago

As the error states, "save()" expects a model instance as parameter.

You want the "create()" method on the relation:

gator left a reply on Call To A Member Function GetClientOriginalName() On String • 1 year ago

The file is not getting uploaded:

  1. Make sure you have enctype="multipart/form-data" on the input form.
  2. Check if file is, in fact, getting uploaded using:
if ($request->hasFile('image')) {

23rd July, 2017

gator left a reply on Pagination And Parameters Other Than ?page=x • 1 year ago

The internals about how '&' and '?' are added to the url is in the source code:

Yes.. using Request::except('page') is fine and it reduces maintenance ..i.e. if you add/delete query parameters, you do not have to change the pagination code.

22nd July, 2017

gator left a reply on Pagination And Parameters Other Than ?page=x • 1 year ago

"appends" literally appends the array that is passed in as parameter. So,


does what you need.

Now, the links() method already generates a "page" query string parameter. So, we need to exclude that when chaining to links(). Request::except('page') gives you an array of all the querystring parameters EXCEPT the page parameter.

i.e. when the url is

Request::except('page') returns


which is what you want to append.

3rd July, 2017

gator left a reply on Struggling To Understand The Concepts Of Laravel And Frameworks, Can You Help? • 1 year ago

If I were in your place, I would just learn the basics of laravel and recreate one of your projects using Laravel.

This will hopefully give you an appreciation of what Laravel brings to the table vs old vanilla php. Don't try to fight it.. these are all industry best practices and they are being widely used due to the benefits they provide.

If you are like me, as you use it more and more, lots of light bulbs will start going off in your mind and very soon, you will "see the light" :-) good luck!

14th June, 2017

gator left a reply on Forms In Blade • 1 year ago


 {{ Form::label('Week Ending') }} 
{{ Form::date('week_ending', null, ['id'=>'week_ending','minimum' => '2017-06-04', 'step' => '7'] )}}

6th June, 2017

gator left a reply on Equation In Laravel Where Condition • 1 year ago

This is best handled by using a Stored Procedure.. Ideally, you want to keep "data related work" within the database. Read up on Stored procedures, query plans and query cache to learn more. Here's what a general solution would look like :

Step 1: create the SP on your server:

create procedure RowsWithinRadius
    lon double, 
    lat double, 
    radius double
    select * from coordinates_table where (abs(lon-longitude)/abs(lat-latitude)<=radius);

Step 2: Once the stored proc is in place, run a raw sql query from Laravel:

public function getRowsWithinRadius($lon, $lat, $radius)
    $results = DB::select( "call RowsWithinRadius($lon, $lat, $radius)");

3rd June, 2017

gator left a reply on How Does Laravel Use The Session In Framework Itself • 1 year ago

@Snapey, you are right. Web requests only. I missed the API group as I was looking at the source code of Laravel 5.0 :-)

gator left a reply on How Does Laravel Use The Session In Framework Itself • 1 year ago

When in doubt, always go to the source.. Here is the starting point :

  1. In App\Http\Kernel, Global middleware Illuminate\Session\Middleware\StartSession is called (this happens for EVERY REQUEST)

  2. The constructor (StartSession class) instantiates the appropriate \Illuminate\Session\SessionManager based on your config settings (defaults to file)

  3. Notice comments inside the handle method of the StartSession middleware: // Note that the Laravel sessions // do not make use of PHP "native" sessions in any way since they are crappy.

And so on..

19th May, 2017

gator left a reply on Populate "old" In Controller • 1 year ago

This is one of the main reasons, I continue to use LaravelCollective Forms. Form::model handles all this for you!

Throw in a bunch of combo/list boxes and/or check/radios, and plain html in the view can get hairy (esp. edit mode).

So, unless I am using a javascript framework, or dealing with a couple of simple textbox inputs in my form, I avoid plain html & "old()" in the interest of cleaner views.

1st May, 2017

gator left a reply on Know Password • 1 year ago

Did you use bcrypt on top of the generated passwords? If so, you can't .. Salted hashes are one-way and cannot be reversed.

If you stored just the random string generated by faker::password, the generated string is the password.

25th April, 2017

gator left a reply on Compatibility Between Laravel Versions? • 1 year ago

Yes.. unfortunately, API breakages between versions do happen more often than I like. As a side effect of this, getting online help (blogs, tutorials etc.) on something becomes tedious and error prone. Given that maintaining backward compatibility is not a priority at Laravel, I personally update the framework version on production code ONLY if I absolutely require a particular feature, AND I have a full test suite to back me up.

8th April, 2017

gator left a reply on Getting Video From Storage Directory • 1 year ago

Another issue I noticed with having a "" source to a route that contains:

//code for getting video from the storage directory
return Response::make($fileContents, 200); 

is that session info somehow gets deleted (i.e. user gets logged off automatically) - this happens randomly, further complicating troubleshooting :-(

Any insight on how this can be avoided? Placing the video files in "public" folder solves this problem.

4th March, 2017

gator left a reply on For What Is The Local Storage? • 1 year ago

Local storage is storage local to your file system, usually under the "app/storage" folder. It can be used for serving/receiving any type of file.

Consider for example, you have an application that stores users resume's. Now, you would not want to store documents directly in the public folder - because if you did, they can then be viewed by anyone on the internet (a web server will serve ANY file stored in the public directory completely bypassing the framework).

So, when the user uploads his/her resume, you move it into app/storage/resume folder. Then, based on your logic, authorization etc, you would create a route that returns response->download() or response->stream() from the storage folder.

I hope this helps!

3rd March, 2017

gator left a reply on Using Scp To Download Files From Remote Server? • 1 year ago

Tinker and exec run with your privileges, access to your stored keys etc.. this is not true when you run from browser or cron.

Have you tried ssh2_scp_recv ? (

6th January, 2017

gator left a reply on How To Work With Monolog-mysql ? • 1 year ago

@dhaval , please refer to the source code of Monolog:

There is sample code in the comments.

5th January, 2017

gator left a reply on How To Work With Monolog-mysql ? • 1 year ago

Laravel itself uses App::environment() for the context. Here's a link to the source code:

So, you could use

$logger = new \Monolog\Logger(App::environment());

A better approach would be to use the endpoint provided by laravel to extend monolog (using monolog-mysql):

NOTE: The creator of Monolog details why using mysql as the sink for logging is a bad idea: Be sure to review and take that into consideration.

1st January, 2017

gator left a reply on Database Engine Keeps Referring To Default Mysql. • 1 year ago

I'm guessing you haven't changed/created environment variables (in your .env file).

In .env, create new vars (something like..):


and use those in mysql2 (database.php).

Hope this helps!

10th December, 2016

gator left a reply on Laravel5 + MS SQL Server + Linux • 1 year ago

@fabiohvieira , You need mssql, freetds and pdo_dblib

22nd November, 2016

gator left a reply on Reading Data From Mysql Views • 1 year ago

Here's how I retrieve data from a view:

 $rows = \DB::select('select * from vw_MyView');
    foreach ($rows as $row) {

20th November, 2016

gator left a reply on Global Filter For POST Requests • 1 year ago

There is an 'ismethod()' function on the request object that can detect post requests:

So, an outline for what you require can be:


namespace App\Http\Middleware;

use Closure;

class CheckBadwordsInPost
    public function handle($request, Closure $next)
        if ($request->isMethod('post')){
            if($this->hasBadWords($request->all())) {
                return redirect()->back()->with('error', 'Disallowed content found. Please Revise');;
        return $next($request);
    private function hasBadWords($formFields){
        foreach ($formFields as $field => $value) {
            //logic for detecting disallowed content here
            return true;
        return false;

Add this to the global middleware (web) Hope this helps.

19th November, 2016

gator left a reply on Static Or Not ? • 1 year ago

Hmm.. Statics are generally hard to test using regular testing tools (phpunit for ex.)

Lets say you create a seemingly innocent static method like so:

public static int square($x)
    return $x*$x;

This is trivial to test .. just set up your expectation and assert that the square of the number is returned.. easy peasy.

Now, lets say you have another class/method, and within that you call :

$sqr = Class::square(10);

There.. now you have a problem on your hands! Unit testing a method that invokes a static can be problematic. Testing the above method in "isolation" requires use of other tools since there is no way to inject functionality (which would have been possible if you used an object to implement the same thing)

Hence the general guideline is to avoid statics in oop.

Edit Your Profile

Want to change your profile photo? We pull from