StormShadow

StormShadow

Member Since 5 Years Ago

Experience Points 93,725
Experience Level 19

1,275 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 1153
Lessons
Completed
Best Reply Awards 21
Best Reply
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.

17 Jul
2 years ago

StormShadow left a reply on Thousands Of Token Exceptions - Possible Bot?

Hi @Snapey thanks so much for the reply. I will see if I can get their IP by logging the request data in my Exceptions handler. Also I'm curious what route they are hitting.

StormShadow left a reply on Thousands Of Token Mismatch Exceptions

@jlrdw I can do that if no one minds the double post

StormShadow left a reply on Thousands Of Token Mismatch Exceptions

This is obviously some kind of automated bot because of the timing of the requests. Also we don't normally get that many requests!

StormShadow left a reply on Thousands Of Token Mismatch Exceptions

Hi @jlrdw thanks for the reply. Yes token is working fine.

StormShadow started a new conversation Thousands Of Token Mismatch Exceptions

Hi everyone!

I've been looking over the logs of a site I help out with. It is a Laravel 5.1 site. I see in the logs the last few days around 6000 to 8000 Token mismatch Exceptions in the logs all happening in the middle of the night. Unfortunately I don't know what is causing it nor do I have any info on what route they are hitting. Is there anything I can do to stop this? What do you think this is? Thanks so much. Any info would be much appreciated.

14 Jun
2 years ago

StormShadow left a reply on Converting Foreign Key To Eloquent Instance

I solved it. Turns out that i was having a problem because my foreign key was the same name as my relation.

Works:

 public function fromUser()
    {
        return $this->belongsTo(User::class, 'from');
    }

Does not work:

 public function from()
    {
        return $this->belongsTo(User::class, 'from');
    }

StormShadow started a new conversation Converting Foreign Key To Eloquent Instance

Hi everyone!

Given this table (called threads):

+------------+------------------+------+-----+---------+----------------+
| Field      | Type             | Null | Key | Default | Extra          |
+------------+------------------+------+-----+---------+----------------+
| id         | int(10) unsigned | NO   | PRI | NULL    | auto_increment |
| to         | int(10) unsigned | NO   |     | NULL    |                |
| from       | int(10) unsigned | NO   |     | NULL    |                |
| subject    | varchar(255)     | NO   |     | NULL    |                |
| created_at | timestamp        | YES  |     | NULL    |                |
| updated_at | timestamp        | YES  |     | NULL    |                |
+------------+------------------+------+-----+---------+----------------+

The fields to and from are user ids from the users table how can set up eloquent relationships or queries so this works:

$thread->to  = the proper Eloquent instance of User instead of just the numerical user id
$thread->from  = the proper Eloquent  instance of User instead of just the numerical user id

Thanks for your help!

08 Jun
2 years ago

StormShadow left a reply on Polymorphic Relationships Customized Eager Loading

I too had this problem as Laravel's new $withCount doesn't seem to work with Polymorphic relationships as of yet. I hope this code will help someone down the line.

  public function likesCount()
    {
       return $this->morphOne(Like::class, 'likeable')
            ->selectRaw('likeable_id, count(*) as aggregate')
            ->groupBy('likeable_id');

    }

    public function getLikesCountAttribute()
    {

        $this->load('likesCount');

        $related = $this->getRelation('likesCount');

        return ($related) ? (int) $related->aggregate : 0;
    }
20 May
3 years ago

StormShadow left a reply on Fetch Posts Of Logged In User And People He Is Following Orderby Date

@bootstrapguru see here for a nice example of a single eloquent query that can be adapted for your use

StormShadow left a reply on Fetch Posts Of Logged In User And People He Is Following Orderby Date

Yeah no worries! You posted while I was typing lol Cheers! Yeah that would be great if there was a single query, If you come across one please share :)

StormShadow left a reply on Fetch Posts Of Logged In User And People He Is Following Orderby Date

@bootstrapguru one way you could do it is

$user = Auth::user();
$userIds = $user->followers->pluck('id')->toArray();
$posts = Post::whereIn('user_id', $userIds)->orWhere('user_id', $user->id)->orderBy('created_at', 'DESC')->get(); 

StormShadow left a reply on [5.2] Make:auth Not Adding Middleware => Web As Shown In Laracasts

@s_chahal in newer versions of Laravel, the call is not necessary anymore in routes.php, it is handled automatically in the RouteServiceProvider

The error you're getting is discussed here

Hope this helps.

14 May
3 years ago

StormShadow left a reply on Auth::user() Versus Auth::User->select('id', 'name')->get()

User::all() returns all of the rows in your user table. If you want the details of the current user

$user = Auth::user():
 $id = $user->id;
 $name = $user->name;
 dd($user); //dump the Eloquent User object. 
09 May
3 years ago

StormShadow started a new conversation Model Events In Tinker?

I don't seem to get model events when I'm using tinker. Haven't tested this much but I am not getting the 'deleting' event. They fire normally when using the browser. Is it just me or is this normal?

08 May
3 years ago

StormShadow left a reply on Adding View Count Error

@Eco012390

Post::where('id', $id)->update(['view_count' => 1]);

however don't forget you can do this:

Post::where('id', $id)->increment('view_count');

06 May
3 years ago

StormShadow left a reply on Cannot Post To Database From Form

No worries, glad I could help out!

StormShadow left a reply on Cannot Post To Database From Form

You can use artisan to generate a class

php artisan make:model SomeModel

The class name can be whatever you want but the idea is that you will map a class to a table in your db. Laravel uses a convention such that the class 'Post' maps to a 'posts' table however you can use whatever class name you want, just be sure if you don't use the convention put this in your model:

        protected $table = 'whatever';

It's all explained on this page https://laravel.com/docs/5.2/eloquent#eloquent-model-conventions

StormShadow left a reply on Cannot Post To Database From Form

Do you have a namespace set on your Userq class? In Laravel, it's usually 'App' so in your route you'd have to use the fully qualified class name:

$userq = new App\Userq();
05 May
3 years ago

StormShadow left a reply on DO Droplet Upgrade Question

Actually just finished doing the resize just this moment, was very smooth and quick process and it looks like it's running as it should! It's 4am, wanted to minimize the downtime impact to users. I'll post here if I find any irregularities. Also was a bit nervous that there was going to be issues with the resize so I took a snapshot before I did the resize. Thanks again for the advice.

04 May
3 years ago

StormShadow left a reply on DO Droplet Upgrade Question

@Snapey thanks, that's good to know. No I hadn't read that I had to fix things, just trying to think of possible situations as its for a production site. Thanks again!

StormShadow started a new conversation DO Droplet Upgrade Question

Hi everyone!

The time has come for me to upgrade my Digital Ocean droplet. I have found a guide I can follow however, if any of you have any hard earned tips I'd love to hear them!

One question I had was do I have to reapply my folder permissions on the upgraded droplet?

Thanks very much!

30 Apr
3 years ago

StormShadow left a reply on Blade Equivalent Isset($v) ? 'string'.$v : ''

{{ $block->name }} {{ isset($block->name_alt) && !empty($block->name_alt) ? '/' : '' }} {{ $block->name_alt }}
10 Apr
3 years ago

StormShadow left a reply on Photo Upload Before Parent Model Created

2 ideas for ya:

  1. dynamically add hidden form inputs for each Ajax response from plupload so that you can reference the photos when you submit the form to create the car

  2. run a cron job that deletes photos from file system / db when they are not associated with a car after a given period of time

02 Apr
3 years ago

StormShadow left a reply on Queues Working Without Running `queue:listen`

@gmanish Good that you got it sorted. I'm using beanstalkd on a forge server for queues, works great and all my mails are queued with Mail::queue to Mandrill

01 Apr
3 years ago

StormShadow left a reply on Queues Working Without Running `queue:listen`

@gmanish is 'database' in your .env for QUEUE_DRIVER? If so that's weird ... perhaps Laravel defaults to sync driver for local dev? Sorry haven't looked into this yet.

27 Mar
3 years ago

StormShadow left a reply on After First Deploy Laravel Add Changes On Database/migration

Yes, you have to run the artisan command to apply your migrations. Just add your new migration file to git and then run php artisan migrate as part of your deploy script. Laravel will only apply the migrations that haven't been already run so it's ok to run the command at any time.

StormShadow left a reply on Forge / DO Server Size And Beanstalkd Workers

@jekinney nope as in you don't know or nope as in he should be good to go with 50 workers? I'm interested in this as well. Thanks !

06 Mar
3 years ago

StormShadow left a reply on How To Get Auth User On Ajax Call?

@kaju74 Sorry I didn't pickup from your original question that you were talking about API :)

StormShadow left a reply on How To Get Auth User On Ajax Call?

No that's wrong. If you have an authenticated user, Auth::user() returns the user even if you use Ajax. I do it all the time. :)

StormShadow left a reply on How To Get Auth User On Ajax Call?

@kaju74 Yep, authenticated user is the same in Ajax request or normal request.

StormShadow left a reply on MethodNotAllowedHttpException In RouteCollection.php Line 219:

@ARAGORND7 yeah sorry I thought you could login via Auth::attempt with just an email, which may be undesired for security, but I just looked at the docs and actual Laravel code and as @DPJack mentioned above you do need to provide a password if you use that Auth::attempt method. Use @skliche's method or a similar query to check if an email exists. You could even do it in your validation step via the exists validation rule.

Sorry, I didn't mean to presume anything about your app :)

StormShadow left a reply on MethodNotAllowedHttpException In RouteCollection.php Line 219:

@ARAGORND7 its because you are redirecting to /password/reset/store (a POST route) when you should be redirecting to /password/reset/form (a GET route)

Also if I may you have a security hole in your code because it allows anyone to login to your app if they know someone's email address. You can fix this by either looking up the user in your validation, via the database or this (does not login the user)

Auth::attempt(['email' => $request->email], false, false)

The parameters are $credentials, $remember, and $login

Hope this helps.

25 Feb
3 years ago

StormShadow left a reply on Mandrill Will Cease To Be FREE

@bashy yeah I'm going to do that. Regarding the DNS changes, do I simply remove my Mandrill DNS entries at the same time as I add the Mailgun DNS entries? How long would that change propogate usually and will the DNS change affect my emails' deliverabilty ? Thanks, don't have much experience with this.

23 Feb
3 years ago

StormShadow left a reply on Beanstalkd Headache

Good stuff Joe!

22 Feb
3 years ago

StormShadow left a reply on Beanstalkd Headache

I'll just throw this out there: are you sure you installed the pda/pheanstalk composer package and also set QUEUE_DRIVER to beanstalkd in your .env?

21 Feb
3 years ago

StormShadow left a reply on Eloquent Insert From Select

@Birdy whoops looks like there is a Laracasts forum bug because I received your reply via Email as I was subscribed to the thread but I cant see it on here, oh well.

To answer your question if you want to query the DB in Laravel, use either Query Builder or Eloquent. You can use Eloquent when you have a class that represents a table. If you don't have this, or you want to interact with the DB in another way use Query Builder. There are different methods unique to QB and Eloquent and they also share some. Also you are not stuck using one or the other you may use both at the same time. Take a look at the docs for a lot more info on this. Since I dont think you using a class to access your saved_estimatiuons, Id say you will need a QB query

i need to figure a way to check if there is already 5 rows inserted in the saved_estimations table with the same following fields: project_id, category_id, property_value_id and if there is then either update them or skip the process entirely and move to the next step. I have tried a few different ways but not yet found a way to get this work.

Perhaps something like this?

$bids = DB::table('saved_estimations')->where([ 'project_id' => $project_id, 
'category_id' => $category_id,  
'property_value_id' => property_value_id])->get();

if( $bids ) {
  
   return view('your-view', compact('bids'));

} else {

    $inserts = [];

    $bids = [insert your random query here]

    foreach($bids as $bid) {
        $inserts[] =  ['project_id' => $project_id,
            'category_id' => $bid->category_id,
            'service_providers_id' => $bid->service_providers_id,
            'bid_price' => $bid->bid_price,
            'property_value_id' => $property_value_id]; 
    }

    DB::table('saved_estimations')->insert($inserts);

     return view('your-view', compact('bids'));
}

Let me know if this helps or if you have any more questions :)

StormShadow left a reply on Node Socket.js Not Working With Https

@wowrudy did you sort this out yet? I'm interested in this as well

StormShadow left a reply on Eloquent Insert From Select

No problem at all! Good luck with your learning and with your project! Laravel is one of the best frameworks out there, once you know the basics it is incredible how productive you can be. It appeals to both novice and experienced programmers alike. As with all things in the dev world there is so much to know, almost too much for any one person! The best we can do is take one day at a time and support one another in the journey.

Cheers mate

StormShadow left a reply on Eloquent Insert From Select

@Birdy I just saw your code above. That would work but the problem is you would be doing an insert for every result. I think it would be better to just build up an array and do the inserts all in one go.

StormShadow left a reply on Eloquent Insert From Select

@Birdy First of all no problem, happy to help! Secondly welcome to Laravel!

Yes try to minimize database queries when you can. Laravel has a way to do multiple inserts in a single query. If you look at the docs you want to do something like this (in this case it is inserting two rows at once) :

DB::table('users')->insert([
    ['email' => 'taylor@example.com', 'votes' => 0],
    ['email' => 'dayle@example.com', 'votes' => 0]
]); 

So what you have to do is first get the results from your random quote query that you are passing to your view. Then loop through the results and build up an array containing all of the data you need to insert into your saved_estimations table.

So I'm guessing something like this

//initialize array $inserts = [];

$bids = [insert your random query here]

foreach($bids as $bid) { $inserts[] = [ 'project_id' => $projects->project_id, 'providers_id' => $providers->providers_id, 'category_id' => $projects->category , 'bid_price' => $bid->bid_price]; }

DB::table('saved_estimations')->insert($inserts);

DB::table('saved_estimations')->insert(array( 'project_id' => $projects->project_id, 'providers_id' => $providers->providers_id, 'category_id' => $projects->category 'bid_price' => BidsTable::orderBy('bid_price', 'desc')->first()->bid_price ));

20 Feb
3 years ago

StormShadow left a reply on Eloquent Insert From Select

@Birdy

Yes, you'd have to save the estimates somehow in another table, because as you mentioned that's the only way of guaranteeing that every time the client views the estimates they are the same and not random.

One approach could be: in the controller see if the records exist in the saved_estimations table for that quotation request id, if so return them to the view. If they don't, generate them with your random query, save them in your saved_estimations table and return them to the view. The next time the controller is hit, they will exist and be returned.

Hope that helps

17 Feb
3 years ago

StormShadow left a reply on Config:cache Makes Variables In .env Null

@skovmand

Relevant ?

If you are using the config:cache command during deployment, you must make sure that you are only calling the env function from within your configuration files, and not from anywhere else in your application.

If you are calling env from within your application, it is strongly recommended you add proper configuration values to your configuration files and call env from that location instead, allowing you to convert your env calls to config calls.