44 Best Reply Awards

  • Member Since 2 Years Ago
  • 468 Lessons Completed
  • 0 Favorites

30th August, 2018

Talinon left a reply on Handling Major Feed Import Timeout Issues • 3 weeks ago

You are correct in your thinking that importing the elements to the database using a bulk query is significantly faster than inserting a single record at a time. From what you've provided, I would be inclined to think the bottleneck might be in the first step, where you are reading the XML file. How long does the script take if you exclude the ProcessFeed::dispatch() job?

29th August, 2018

Talinon left a reply on Factory Inside Factory, How To Pass Attribute For All Nested • 3 weeks ago

I haven't tested it, but I think something like this would work:

$factory->define(\App\Comment::class, function (Faker $faker, $overrides) {
   $word = $overrides['word'] ?? $faker->word;

    return [
        'rand_string' => $word
        'post_id' => function(){
            return factory('App\Post')->create(['rand_string => $word])->id


$factory->define(\App\Post::class, function (Faker $faker, $word) {
    return [
        'rand_string' => $word ?? $faker->word


Talinon left a reply on Factory Inside Factory, How To Pass Attribute For All Nested • 3 weeks ago

$factory->define(\App\Comment::class, function (Faker $faker) {
$word = $faker->word;

    return [
        'rand_string' => $word
        'post_id' => function(){
            return factory('App\Post')->create(['rand_string' => $word])->id


$factory->define(\App\Post::class, function (Faker $faker, $word) {
    return [
        'rand_string' => $word


Talinon left a reply on How Do You Logically Group Tests For A Resource? • 3 weeks ago

This is something I often question myself, too.

I think it comes down to a question of what makes the most sense for the project? If it is a fairly simple CRUD resource, does it make sense to break up a dozen tests into 6 different test classes? I would argue: no, it doesn't make sense.

Personally, I try to keep them all included into a single class, and have that entire class read like documentation for the resource. Admittedly, I have some test classes that probably have 50+ tests, but I don't see the harm in that, as long as they're all tests for the same feature. We're talking about tests, not production code - I don't think it's something to be overly concerned about.

I sometimes use the setUp() method as a guide for when to break tests up into other classes. If I find that I'm unnecessarily running a lot of setup code for tests, that might be an indication they should be moved into a test class that has less setup work (or more appropriate setup work).

For the class name itself, I usually just keep it simple and use the convention of <Resource-name>Test. If I'm creating a class that tests something beyond the scope of a single resource, or integration tests, that is when I usually decide to create a new test class, and I'll name it something along the lines of Test. can even be several words, to make it clear what the test class is responsible for.

28th August, 2018

Talinon left a reply on AssertHasOldInput() Missing Since 5.4 • 3 weeks ago

Well, I'm not sure what happened, but the guides states it makes every effort to document every change, but sometimes minor or obscure changes get missed.

The source for the assertHasOldInput() was basically just a helper function, so you could always add this as your own helper. You could even place it within your base TestCase.php file.

     * Assert that the session has old input.
     * @return void
    public function assertHasOldInput()

27th August, 2018

Talinon left a reply on Global Partial Routes On Resources • 3 weeks ago

You should be able to do this:

Route::resource('breeds', 'BreedsController', ['only' => ['index', 'store', 'show', 'update', 'destroy']]);


21st August, 2018

Talinon left a reply on CURL Error 6: Could Not Resolve Host • 4 weeks ago

Can you show the code where you instantiate $http?

Talinon left a reply on No Debug Page ( Debug Is True ) • 4 weeks ago

i already ran cache:clear command ..still getting the same results

It was suggested you run php artisan **config**:clear - just want to make sure you're aware there are two separate commands.

20th August, 2018

Talinon left a reply on No Debug Page ( Debug Is True ) • 1 month ago

It may be because of your default file permissions. Check the storage/logs/laravel.log file to see what the last error was. If there is nothing written to the log, then it is almost certainly due to permissions on your storage/directory.

18th August, 2018

Talinon left a reply on Factory Each Closure With Belongs To Relation • 1 month ago

You are associating a Contact instead of an Address:


Talinon left a reply on Factory Each Closure With Belongs To Relation • 1 month ago

I don't see anything immediately obvious that would be a problem. What doesn't work about it? Does it throw an error? or does it just not set the foreign key?

What is the code for your address relationship on your Employee model? Does it return a BelongsTo relationship to the Contact class?

Talinon left a reply on Multiple Middlewares Do Not Work As Wanted • 1 month ago

You might find it more convenient to define your middleware on your routes, or to route groups. I prefer this, opposed to adding them to all the controller constructors.


16th August, 2018

Talinon left a reply on How To Use NotIn Function And Case Insensitive Together? • 1 month ago

You should be able to do something like this:

'keyword' => [Rule::unique('groups')->ignore($group)->where(function ($query) use ($group) {
                return $query->where('org_id', '=', $group->org_id);
            function($attribute, $value, $fail) {
                     if (strtolower($value) === 'cancel') {
                                return $fail("Keyword 'Cancel' is invalid");

If you are going to have a re-use for the closure, you can always extract this to its own custom Rule object.

15th July, 2018

Talinon left a reply on URL Rewrite • 2 months ago

First, for the routes, even though I don't think performance would take a hit, I'm sure you could consolidate them with a required route parameter.

Something like:

Route::get('/module/lesson/{page}, '[email protected]');

Then within your LessonController, you can render the appropriate page.

public method show($page) {
    return view("module.lesson.{$page}");

As for not allowing your users to jump ahead, you have a few options.

I You might be able to handle this as simply as with a session variable. In the LessonController, update a Session variable that is responsible for keeping track of the last page the user has completed. When the user requests a new page, check to make sure it isn't greater than lastpage+1, otherwise handle it with some kind of exception, redirect, etc. This method may be a more appropriate option for a timed-lesson. The disadvantage is that if the user logs off, the session variable would be cleared, and they would need to start over.

If you want to avoid the session option, then you'd need to resort to some kind of persistence: either to a database, or perhaps a in-memory data store like Redis. If you don't have a lot of traffic, using the database might not be a terrible option.

14th July, 2018

Talinon left a reply on URLs For Controller Actions With Parameters With Form Submit • 2 months ago

I would suggest going thru the excellent free series that this website provides.


Talinon left a reply on Best Practice For Handle Edit Requests When User Is Not Exist • 2 months ago

Well, another option would be Route Model Binding.


Route::get('users/edit/{user}', '[email protected]');


use App\User;

public function edit(User $user)

    return view('manageuser.edituser',compact('user','roles'));

By type-hinting the User Model in your controller function, it will automatically bind the User model using the id. If the user doesn't exist, it will throw a HTTP 404 error (not found). This essentially does the same thing you're trying to do above, but in a much cleaner fashion.

If you don't want to have the error to default to a 404 error page, you will need to catch the ModelNotFound exception. You can read more about that here:


13th July, 2018

Talinon left a reply on Queue:work Not Responding • 2 months ago

Yeah, I figured it was because of a named queue. You can also process them by specifying the queue name: ``` php artisan queue:work --queue=emails``

Talinon left a reply on Queue:work Not Responding • 2 months ago

Does the 'queue' column on your jobs table have 'default' for the values?

Talinon left a reply on Queue:work Not Responding • 2 months ago

Since Laravel 5.3, the queue:work defaults to daemon mode, so it is behaving properly. If you specify the ''--once'' option, it will process the first job that comes along and then self-terminate. If you want to fork it into the background when you run the command, just add an & to the end of the command: php artisan queue:work &

10th July, 2018

Talinon left a reply on Update With Save() Doesn't Work • 2 months ago

Do you have a primaryKey specified on your model?

protected $primaryKey = 'someColumn';

Talinon left a reply on Update With Save() Doesn't Work • 2 months ago

Are you sure you are actually getting a DeliveryTime record with your where condition? Try firstOrFail() to check?

$deliveryTime = DeliveryTime::where('key','=',$key)->firstOrFail();

Talinon left a reply on Queue Job Is Not Finishing • 2 months ago

From Laravel 5.2 to 5.3, there were some database changes to the jobs table. You might want to look into that section of the upgrade notes under "Database driver changes" to see if that is your issue:


9th July, 2018

Talinon left a reply on How To Use Mockery For A Class Used In A Controller? • 2 months ago

I think you're under the impression that Mockery wields some magic where it can alter your source code with a mock. This is not the case - your test post will still execute your source code exactly as you have it.

Instead, in your test, you can swap out the underlying Newsletter class by calling swap() on the facade.

use Spatie\Newsletter\Newsletter;
class NewsletterTest extends TestCase {

    use RefreshDatabase;

    public function setUp()

    public function tearDown() {

    /** @test */
    public function a_guest_can_subscribe_to_newsletter() 

    $mock = \Mockery::mock(Newsletter::class)->shouldReceive('subscribePending')->once();  


        $this->json('post', route('newsletter.store'), ['email' => '[email protected]'])

The above test will swap your underlying Newsletter class with a mock (for the duration of the test), that expects the function subscribePending to be called exactly once. If the function doesn't get called, Mockery will throw Mockery\Exception\InvalidCountException

Keep in mind, this does not test anything, other than the fact that at some point in your stack, Newsletter::subscribePending() gets called.

You could do the same with a service provider, or anything bound in the Laravel Service Container.

    $mock = Mockery::mock('someClass'); // chain on method calls
    app()->instance('someClass', $mock); // bind the mock object into the Service Container

Now whenever 'someClass' gets resolved out of the Container, it will be your mock, not your source object.

Hope this helps you better understand how Mockery works.

8th July, 2018

Talinon left a reply on Validate Form Served Via AJAX Call Using JQuery Validation • 2 months ago

I think what is going on is when you replace the login form within the DOM, the original elements that have event listeners are removed. When you replace it with the 2fa content, JQuery doesn't have event listeners attached to the freshly added content.

Perhaps you can solve this by wrapping the 2fa form query javascript into a function, and then call it in your AJAX success function.

Something like:

// 2fa form jQuery
function 2fa(
    $(document).on('click', '#submit-btn', function (e) {

          success: function(data) {
                if (data.intended) {
                    window.location.href = data.intended;
                } else {
            2fa();  // load event listeners for the new content

6th July, 2018

Talinon left a reply on Collection Property Does Not Exist • 2 months ago

When you get a collection from a model, you're getting an eloquent collection, which allows you to access the data as object properties. When you use collect(), this is a support collection, and is a bit different.

For a support collection, you can use get()

Such as: collect(['one' => 1, 'two' => 2, 'trhee' => 3])->get('one');

4th June, 2018

Talinon left a reply on Validating JSON API Request With Laravel 5.6 • 3 months ago

The problem is with your validation rule array. Try this:

$validator = Validator::make($request->json()->all(), [
            'code' => 'required',
            'description' => 'required',

31st May, 2018

Talinon left a reply on Favorite Testing Methodology? • 3 months ago

@jlrdw Even though interesting, your link is regarding NASA Test Pilots :)

Talinon left a reply on How To Enable Dusk Test, Open Chrome To View The Whole Process • 3 months ago

I think you just need to remove the --headless option from the driver() method within DuskTestCase.php:

protected function driver()
        $options = (new ChromeOptions)->addArguments([
//            '--headless'

        return RemoteWebDriver::create(
            'http://localhost:9515', DesiredCapabilities::chrome()->setCapability(
                ChromeOptions::CAPABILITY, $options

Talinon left a reply on Validating Array Of Input Fields Not Working In Firefox. Chrome Okay • 3 months ago

looks like you're missing an equals sign:

<form method="post" action="{{ route('file.store') }}" enctype='multipart/form-data' files="true">

17th April, 2018

Talinon left a reply on How To Change ISO_8601 In UTC To Mysql Timestamp • 5 months ago

I'm not exactly sure what you're trying to do.. Is it important that the actual data within the database is in ISO_8601 format, or do you just need it converted for application logic?

If you are just looking for a way of working with the timestamp within your application, you might want to look into Carbon (it's included with Laravel)


To take it a step further, if you wish to always have a Carbon instance of your my_date field, you can create a Model accessor within your User model:

public function getMyDateAttribute($value)
    return \Carbon\Carbon::parse($value);

This way whenever you try to access $user->my_date you will get a Carbon instance of your date/timestamp, and you can do whatever you wish with it.

13th April, 2018

Talinon left a reply on How To Create An Array Only Generate Certain Rows In A Table • 5 months ago

$roles = Role::pluck('role_name', 'id')->except(['role_1', 'role_2']);

Talinon left a reply on How To Group Multiple Fields Under Validator->sometimes Validation? • 5 months ago

Recently I had something similar to this with several sometimes validations. I couldn't think of any practical way to improve upon it other than just refactoring them to their own methods to try to keep it as organized and descriptive as possible.

Talinon left a reply on Laravel 5.2 -> Laravel 5.6 Framework Upgrade • 5 months ago

Yeah, one step/version at a time. I would make a new branch for each version and just make my way through the change log and test everything.

I upgraded at a pace of one version per week. I'd apply the changes over a weekend, and pray on Monday morning that everything went well. If everything was smooth by mid week, I'd start a new branch and work on the next version.

FYI - laravelcollective/html was removed from the main laravel package, but you can still pull it in through composer to use with any version. I'm still using it with 5.5 without any problems.

Talinon left a reply on Laravel 5.2 -> Laravel 5.6 Framework Upgrade • 5 months ago

I also maintain a corporate intranet that includes mega applications such as CRM, Project Management, POs, among others. I upgraded from 5.2 to 5.5 last year, and it went relatively smooth. I just started off with the upgrade notes for 5.3, and made my way through all the changes. I would run 5.3 on production for a week or so to make sure everything was stable, and then proceed with the next version.

I found upgrading from 5.2 to 5.3 to be the most intensive, the other jumps to newer versions were completely painless.

If by chance you have 100% test coverage, this gives you much more confidence to make the upgrades. IMO, the upgrade was definitely worth it, but that is a decision you need to make on your own.

Talinon left a reply on PHP-Laravel UnitTesting • 5 months ago

Might be worth mentioning that your second post/assertion will only execute if your first assertion passes.

Talinon left a reply on Wildcard In Middleware • 5 months ago

Talinon left a reply on Wildcard In Middleware • 5 months ago

Why not handle it on the routing level?

Route::group(['middleware' => ['api-middleware'], 'prefix' => 'api'], function() {

    // api routes


12th April, 2018

Talinon left a reply on How To Pass One Variable To View • 5 months ago

you could just do:

return view('post.create', compact('id'));

4th April, 2018

Talinon left a reply on Need An Ideal Solution In Queuing Many Many Emails • 5 months ago

Your solution seems fine to me. Your concern about taxing your server with a lot of tasks is exactly why queues exist. Your emails can be queued to be delivered in a controlled and orderly fashion so that other requests to your application are not hindered.

The only thing you may want to consider is the handling of the loop itself. If the scenario you describe is an accurate number of iterations, then you'll be fine.. but if it ends up being something like a million emails, you may want to consider breaking up the loop itself into chunks that also get queued.. but I doubt that will be necessary.

Talinon left a reply on === Operator In Laravel • 5 months ago

It may not necessarily be your code per se, but it could very well lead us to the problem. For instance, where does the data come from that the strict equals operator is used upon? If it's coming from somewhere like a database, it will be driver related, which is what I expect. Probably something is being returned from some driver as a different type than what the driver returns under your xampp environment.

Talinon left a reply on Query By Count Of Relationship Comparison To Parent Field Value • 5 months ago

You should be able to do something like this:

Project::has('users')->with('users')->get()->filter(function ($project) {

    $project_count = $project->users->count();

    return $project->user_count < $project_count;


5th March, 2018

Talinon left a reply on Spitting Results • 6 months ago

It is because you are not passing the member data to the view properly.

Try one of these methods instead:

    return view('welcome', compact('member));


    return view('welcome')->with(['member' => $member]);

9th February, 2018

Talinon left a reply on Call To Undefined Function Mb_strimwidth() • 7 months ago

See if the module is activated by either `<?php echo phpinfo();' or run the command: 'php -i | grep mbstring'?

Talinon left a reply on Call To Undefined Function Mb_strimwidth() • 7 months ago

It sounds like you don't have the Multibyte String (php-mbstring) PHP extension installed.

Running this command should install it on your server:

sudo apt-get install php-mbstring

Talinon left a reply on Division By Zero • 7 months ago

This likely occurs when $figure_votes has a count of 0, so you end up dividing 0 by 0, which is erroneous.

As @tykus mentioned, this seems a bit much for blade, but a quick fix would be to wrap it in an @if directive:

@if ($figure_votes->count())
     {{ number_format($figure_votes->where('figure_id' ,$data->figure_id)->get()->pluck('figure_vote_id')->count() / $figure_votes->count() * 100, 2) }}% 

Talinon left a reply on Execute Shell Commands HELP • 7 months ago

Unfortunately, since HTTP is stateless, it's going to need to get a bit more complex. In order to make the output display to the client in real time, you're going to need to implement something like WebSockets. Something like Laravel Echo might help you.

Talinon left a reply on Why ->exists Property Errors Out On Upgrade From 5.3 To 5.5 ? • 7 months ago

Yeah, I just tested this on 5.4 - when I provide a null default for a model, Laravel ignored it and route model bound it anyway. Starting in 5.5, looks like it honours the actual null and doesn't inject a new model instance. I haven't dived into the code to pinpoint it, but this type of behaviour makes sense to me and was likely an intended change.

Talinon left a reply on Why ->exists Property Errors Out On Upgrade From 5.3 To 5.5 ? • 7 months ago

Hmm. Are you sure that you defaulted $channel = null in the method in 5.3 as well?

By having the method parameter defaulted to null, your first route `photolibrary' would definitely result in channel being $null, and the reason for your object error.

Alternatively, if you did NOT have $channel defaulted to null, Laravel would instead method inject a new model instance of Channel, where the $channel->exists property would be available.

Edit Your Profile

Want to change your profile photo? We pull from gravatar.com.