Talinon

Talinon

Toronto

Member Since 3 Years Ago

Experience Points 106,910
Experience
Level
Lessons Completed 585
Lessons
Completed
Best Reply Awards 78
Best Answer
Awards
  • Start Your Engines Achievement

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • First Thousand Achievement

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • One Year Member Achievement

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • Two Year Member Achievement

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • Three Year Member Achievement

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • Four Year Member Achievement

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • Five Year Member Achievement

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • School In Session Achievement

    School In Session

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

  • Welcome To The Community Achievement

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • Full Time Learner Achievement

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • Pay It Forward Achievement

    Pay It Forward

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

  • Subscriber Achievement

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • Lifer Achievement

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • Laracasts Evangelist Achievement

    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 Achievement

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • Laracasts Veteran Achievement

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • Ten Thousand Strong Achievement

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • Laracasts Master Achievement

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • Laracasts Tutor Achievement

    Laracasts Tutor

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

  • Laracasts Sensei Achievement

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • Top 50 Achievement

    Top 50

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

13 Jan
3 days ago

Talinon left a reply on How To Create Facades On Laravel 5.7 Package

Why are you prefixing your facade accessor with 'gathuku-' ? You want the facade to resolve to the underlying class Mpesa:

protected static function getFacadeAccessor(){

        return 'mpesa';
}

12 Jan
4 days ago

Talinon left a reply on Eager Loading Returning False Relation Data

If we think about this, it makes sense.

First example:

 dd(Product::where('products.id', 1)->first()->userFeedbacks);

You are first fetching a model, and then retrieving the related userFeedbacks.

Second example:

$result = Product::with('userFeedbacks')->where('products.id', 1)->first();

You are not not dealing with any specific model, so how would $this work? Instead, you need to use an Eager Loading Constraint:

$result = Product::with(['userFeedbacks' => function ($query) {
    $query->where('products.id', 1);
}])->where('products.id', 1)->first();
10 Jan
6 days ago

Talinon left a reply on Remove All Cache Files That Has Name 'page-'

Of course you can do it manually, but I was proving you a way of handling it with one call by using tags. If you keep adding pages, are you going to keep manually deleting files every time you need to clear the cache?

Talinon left a reply on Remove All Cache Files That Has Name 'page-'

I don't think there is a way to do this by name. I think the best way to go about this is to use Cache Tags. You would then be able to remove all cache that have the specified tag.

Cache::tags('page-parts')->flush()

https://laravel.com/docs/5.7/cache#cache-tags

09 Jan
1 week ago

Talinon left a reply on How To Create Auto Sequential Number With Prefix

I would also agree to use an accessor.

Something like this would work:

public function number() 
{

    return str_pad($this->id, 5, 0, STR_PAD_LEFT);

}

That will give you the id of the model, prefixed with zeros up to 5 digits in length. If you roll over 09999, it will just continue onward without a preceding zero.

03 Jan
1 week ago

Talinon left a reply on Dispatch Event When Exception Is Triggered

I think I would handle this by wrapping your gateway call within a try/catch block within your controller. Something like this:

public function store(OrderRequest $request, Gateway $gateway)
    {

    try {

        $charge = $gateway->charge($total, $token, $description);

        event(new OrderSucceed($order, $cart, $charge));

    } catch (\Stripe\Error\Card $exception) {

        event(new OrderFailed($order, $exception));

    }



    // return json response 201
    
    }

02 Jan
2 weeks ago

Talinon left a reply on I Can't Pay The Subscription Fee

I would suggest following the "support" link at the bottom of the page to ensure Jeffrey directly receives your request. The support link states that PayPal is an available solution, which should be available to Tunisia.

01 Jan
2 weeks ago

Talinon left a reply on Testing Laravel HTTPNOTFOUND Exception On Second Pass

Do you have multiple route files?

Check out this thread, sounds like it could very well be your issue:

https://stackoverflow.com/questions/23418150/unable-to-run-multiple-controller-tests-in-laravel

30 Dec
2 weeks ago

Talinon left a reply on Subdomain Route Strange Behaviour

If the sub-domain doesn't exist, it wouldn't have a resolvable DNS alias, and the browser would just throw an non-resolvable address error.

If you do have a DNS alias set up for something.subdomain.mysite.test and it's pointed to the same IP as your main application, then that would explain why it loads your root application when you try to access it. The route group code never gets executed since you're trying to access an additional level sub-domain, and it continues to the last line of your snippet and calls [email protected]

if you add a `dd()right after your firstRoute::get(), and then load yoursomething.subdomain.mysite.test``, I bet it will never get called.

Route::group(['domain' => '{subdomain}.{domain}.{tld}'], function () {

    Route::get('/', function($subdomain) {

    dd('i will not be called');
        $site = Site::whereNotNull('published_at')
            ->where('slug', $subdomain)
            ->first();

        return isset($site)
            ? Storage::get($site->identifier)
            : abort(404);
    });
});

Route::get('/', '[email protected]')->name('welcome');

Talinon left a reply on Guidance To Do Validation Of Inputs In A Search Form

You need to add a "use" statement at the top of your controller, or use the full namespace for the typehint in the controller's methods.

use App\Http\Requests\SearchFunction;
29 Dec
2 weeks ago

Talinon left a reply on Need Help With Eloquent One To Many Relationship

That link doesn't work (.test domain)

But, you can access that attribute of the first related model via:

   $posts->postmeta->first()->meta_key;

If you need to access them all, you can loop through them, or pluck them.. I'd suggest looking at all the ways you can interact with Eloquent Collections here:

https://laravel.com/docs/5.7/eloquent-collections#available-methods

Since the original thread subject is solved, please mark the best answer.

Talinon left a reply on Need Help With Eloquent One To Many Relationship

Your problem is here:

public function postmeta()
    {
        return $this->hasMany(PostMeta::getMeta, 'post_id', 'ID');
    }

Change that to:

public function postmeta()
    {
        return $this->hasMany(PostMeta::class, 'post_id', 'ID');
    }

The first argument to hasMany() is a string representation of the path to the related model.

Talinon left a reply on Need Help With Eloquent One To Many Relationship

You are not retrieving the fields of wp_postmeta because BelongsTo is a relationship, not a join.

To eager load the relationship, you just need to do something like this within the controller:

$post = Post::with('postmeta')->first();

You will be able to view the fields via $post->postmeta

(I renamed the $posts variable to a singular form of $post just to eliminate any confusion that we're only getting the first)

Talinon left a reply on The Bootstrap/cache Directory Must Be Present And Writable On Shared Hosting Laravel

Sounds like you manually deleted the bootstrap/cache directory? Just re-create it and the artisan commands should stop throwing that error. Run from your project root: mkdir bootstrap/cache and make sure the permissions are set properly.

21 Dec
3 weeks ago

Talinon left a reply on Data Available On Every Page

You could use AppServiceProvider - no problems there. If that provider ends up being a bit cluttered, you could always move it out into another. I sometimes create a ViewServiceProvider for this scenario - but again, I wouldn't worry about it until you have a reason to do so.

Talinon left a reply on Best Practice For Checking Relationship Between Models?

Well, if you bring in route model binding for your Post model, it could be as simple as:

    public function show(Post $post)
    {
        $p = auth()->id() === $post->user_id;
    }
}

If you are looking for an elegant way to control how users may interact with your Post model, I suggest taking a look at policies, where you can place all this logic for CRUD actions.

https://laravel.com/docs/5.7/authorization#creating-policies

Talinon left a reply on Data Available On Every Page

You should be able to clean this up by doing:

$settings = Cache::remember('settings', 60, function()
        {
            return \App\Setting::all()->keyBy('slug');
        });

You could also move the above into a server provider and do the following:

View::share('settings', $settings);

This way, it'll be available to all views, and you can get all that out of your controller. No need to even pass $settings when returning your view()

Talinon left a reply on How To Check Database Every Second With Laravel

Well, commonly what is used to perform scheduled tasks is cron, but the smallest frequency it can be configured to run is every 60 seconds.

So, you would need to either write a daemon that handles this, or, you could still use cron to run a Laravel console command, that loops 60 times using sleep(1).

Talinon left a reply on Are Long Waiting Times A Must Or Bad Development?

@roborobok I never said it was a good reason, just the most likely one :)

Talinon left a reply on Are Long Waiting Times A Must Or Bad Development?

I think it's basically just a disclaimer to cover their behinds, in case something trickles thru. Even though you may have cancelled, you as a recipient of a newsletter might very well be chunked into a stored queue somewhere to be dispatched over the next couple days..

20 Dec
3 weeks ago

Talinon left a reply on Is Resolve-url-loader Needed When Using Less?

Referencing the less documentation @ http://lesscss.org/usage/#command-line-usage-relative-urls

By default URLs are kept as-is (off), so if you import a file in a sub-directory that references an image, exactly the same URL will be output in the css. This option allows you to rewrite URLs in imported files so that the URL is always relative to the base file that has been passed to Less. E.g.

So, I think you'd be fine just using less-loader

Talinon left a reply on Sending Email With Mailgun - Undefined Variable

Looks like you need to include your variable for your closure to have access to it:

Mail::send('email.reklama',$maildata, function($message) use ($email) {
        $message->to($email, 'User')->subject('Email');
      });

Talinon left a reply on Can't Use Php Artisan Tinker With Valet

Try adding the recursive flag: sudo chown -R ....

Talinon left a reply on Better Way Of Doing This

I have used this exactly for this purpose - making an accessor for a description of a status. I reach for this when it makes sense to do so.

Talinon left a reply on Better Way Of Doing This

You could make them a class constant or property and do something like this:


public static $statuses = [
    1 => 'Done',
    2 => 'Not Started',
    3 => 'In Progress',
    4 => 'Stuck'
];


public function getReadableStatusAttribute()
{

    return self::$statuses[$this->status];

}



Talinon left a reply on Tinker History

On second thought, I don't think that will solve your issue, because I have readline support installed. I don't recall going out of my way to install it though.

Talinon left a reply on Tinker History

I use Linux Mint, and my tinker history works fine - but I vaguely recall having a similar issue. I'm trying to rack my brain on how I resolved it - but I remember it was something simple.

Try this: sudo dpkg-reconfigure keyboard-configuration

That might require a reboot to take effect

Talinon left a reply on Canceled Account?

To ensure your message is received, I would suggest clicking on the "support" link at the bottom of the page and let them know directly.

19 Dec
4 weeks ago

Talinon left a reply on Instantiate Abstract Class

Just remove the abstract deceleration from your class. The Crawler docs is saying you should extend the Crawler's abstract class - that does not mean that your class should be abstract. Abstract classes cannot be instantiated.

class myClass extends CrawlObserver {

}

Talinon left a reply on SQL Format Error & Daylight Saving Time

You are correct, UTC does not have DST.

Try this query and see what it comes back with:

SELECT TIMEDIFF(NOW(), UTC_TIMESTAMP);

If you have an offset, your session isn't in UTC. Probably what is happening is when you're performing your query, you're sending a datetime that can't be converted to UTC.

Talinon left a reply on SQL Format Error & Daylight Saving Time

You are correct, UTC does not have DST. Probably what is happening is when you're performing your query, it's being converted to your session's timezone, and if that time is invalid in your timezone, you get the error.

Try this query and see what it comes back with:

SELECT TIMEDIFF(NOW(), UTC_TIMESTAMP);

Talinon left a reply on SQL Format Error & Daylight Saving Time

I'm not sure why you think a missing hour would not matter.

According to MySQL documentation on DateTime:

  • At the start of daylight savings, when clocks are turned forwards, there's a "missing hour". Technically times in this hour aren't valid, but if you do try to store a time from this missing hour in a TIMESTAMP column and then read it back, you WON'T get out what you put in! (Contrary to what the page states).

Talinon left a reply on Laravel 5.5 Logging In /var/log/syslog Instead In Storage/logs/laravel.log

I know you said you checked your config/app.php, just just to confirm, make sure your log configuration is actually using your environment variable:

'log' => env('APP_LOG', 'single'),

If the above is set, make sure you clear your config cache: php artisan config:clear

Talinon left a reply on Add Up/Down Vote Instead Of Best Reply

While on this topic of Best Replies...

I'd also like to see something like a monthly email that is delivered to any thread owners, with a summary of all threads that have not been closed; reminding/encouraging them to return to the thread and select a Best Reply. The email would only list threads that have at least 1 reply, and activity since the previous month. I would say that threads stay open more regularly than those that get closed - and I think that is just another case of the OP not realizing the feature exists.

But - if the Best Reply was driven by votes, this wouldn't matter anyway.

Just something to think about.

Talinon left a reply on Add Up/Down Vote Instead Of Best Reply

The only problem I see with down voting is that it provides a tool to cast negativity. The Laravel/Laracasts community has a reputation for being friendly and helpful, and I'd hate to see a mechanism put in place that could tarnish that (even if deserved, in some cases).

Instead, I'd rather see members be more inspired to "up vote" or "like" good responses, and have that drive the best reply. I think there would need to be some kind of incentive to encourage members to use it, though, as it's currently under used.

Another scenario I see commonly is that the OP doesn't really know what the best answer is, and ignorantly selects a non-so-best reply.

18 Dec
4 weeks ago

Talinon left a reply on Laravel Tinker Error

Did you override the save() method on your model? or, do you have any trait on your model that may be overriding it?

17 Dec
4 weeks ago

Talinon left a reply on Event Is Correct, But Listeners Recived User=null

Not much to go on without any code...

Throwing a dart, your problem might be that you need to access the user via: $event->user

For example, if you made a public user property on your event class:

public function handle(someEvent $event)
{

    $event->user; // here I am

}

Talinon left a reply on MySQL Database Calculate Total Sum

I wouldn't calculate the total value by summing the related lines, even if you store the line extensions. It is still making unnecessary calculations that can significantly slow down your app. Just do all the calculations at the time of saving your model, and store the total on the invoices table. I don't know the scope of your project, but mine quickly escalated into a mess when reporting needed to be broken down by region, territory, sales manager, subsidiary-company, item class, etc. If you're already performing complex queries and filtering, you don't want to have to dive into related lines and do further calculations.

As I said, by having the total on the invoice model, you can still perform your on-the-fly operations, such as reporting, lists, etc, but you can just simply reference the total value - you'll thank yourself for this later on.

You bring up a good point about taxes. So, I would consider having these fields: total, tax, extension all on the model. The fact that there can be multiple types of tax is not lost on me - in situations where that kind of detail would be required is when I'd dive into the related data to gather it - but chances are, if you need that type of data, you're probably "viewing" the invoice and retrieving all the data anyway.

16 Dec
1 month ago

Talinon left a reply on MySQL Database Calculate Total Sum

You could certainly build a query to handle this, but I strongly suggest against it. A few years ago, I had a couple projects very similar to this where I asked myself the same question. Originally, I developed it to calculate on-the-fly, by taking all the sum of all the related lines (quantity * price) - very similar to your situation. As the projects grew, more business logic was required, which added many layers of complexity. For an example, let's take a quotation. The original quote's body might sum up to an amount, but maybe doesn't take into account extra charges, overhead, extension of work, etc. Scenarios like this arose to the need to add a user-specified "total bid value", which if present, would override the lines calculation. You can see how conditionals such as this can easily break-down and cause headaches in trying to go down this road.

Instead, I suggest that at the time of persistence (including update) is when you perform your net total calculation, and then save it as a field on your parent record. This still gives you the ability to perform on-the-fly calculations, but without the overhead of performing costly joins and other additional calculations. I also have some experience with ERP integrations, and many enterprise solutions take this same approach of storing the calculated total.

15 Dec
1 month ago

Talinon left a reply on File Storage Link

Look into your config/filesystems.php file to check what the root configuration is set to for your default disk.

Talinon left a reply on Serialize Computed Property Carbon Instance

If you're using Laravel 5.6+, you should be able to do this:

protected $casts = [
    'depatureTime' => 'date:y-m-d'
];

Which should format the date the way you want when you cast to JSON.

Talinon left a reply on Can Appended Model Attributes Access Related Models?

I think $appends only works when the model is cast to an array or JSON. You should see the value if you take your model and cast it to either, such as: $forecast->toArray()

14 Dec
1 month ago

Talinon left a reply on Laravel Laravel BelongsToMany Fetch One.

You could get the latest status for a user via: $user->stauses()->latest()->first();

Talinon left a reply on Getting Empty ID After Running $model->save()

You said you tried different code to try saving the model, but do you have any hooks for your model's saving event?

Have you tried manually inserting a row into the database outside of your application (CLI, GUI inspector) to see if the database assigns the auto incremented integer?

Apps running PHP 7.1 on the same server return the ID.

You have PHP 7.1 and 7.2 running on the same server?

13 Dec
1 month ago

Talinon left a reply on Video On Model Property Testing

Your question isn't worth debating. If you want to have true test coverage, you write the model test.

Your models are not part of the framework. Your models are extensions of the framework. If there are people who are against testing the code on models, then they shouldn't be using models.

Talinon left a reply on Collection::orderBy Does Not Exist On Concat

orderBy() is a Query Builder method. Once you call get(), you are now working with a collection. You want to now reach for the sortBy() method. You also will need to use take() instead of limit()

$collection = $users->concat($events)->sortByDesc('updated_at')->take(5);

Talinon left a reply on Why Is A Function Necessary In Route::get?

I think what you are referring to is a route closure that ships out-of-the-box. I think he's just illustrating a basic concept at that point within the series. Keep watching, he'll certainly follow up with best practices.

Talinon left a reply on Accessor Causes Tests To Fail

I recently ran into a similar problem to this, and would be interested to know of a solution, too. After messing around with accessors and $casts for about half an hour, I finally just settled on making a supplementary accessor, and left the original date attribute alone.

public function getFormattedDateAttribute()
{
    return Carbon::parse($this->date)->format('M d, y');
}

This allowed the persistence and behavioural tests to pass, and I just referenced this method when I wanted the special format (mostly just for views). I'm not really satisfied with this work-around, but didn't want to waste anymore time on it. I'd be interested to see if someone else has a solution.

Talinon left a reply on SQLSTATE[42S22]: Column Not Found: 1054 Unknown Column 'name' In 'order Clause'

Are you trying to order the collection by the name of the category relationship?

If so, you need to perform a join, something like this:

$posts = Post::join('categories', 'categories.id' ,'=', 'post.category_id')
    ->where('type', 'page')
    ->orderBy('categories.name', 'asc')
    ->paginate(20);