jpeterson579

jpeterson579

Member Since 4 Years Ago

Experience Points 27,725
Experience Level 6

2,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 203
Lessons
Completed
Best Reply Awards 2
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.

11 Dec
4 months ago

jpeterson579 left a reply on Data Type For All Numbers. Ex: 2, 3.3, -2.890, 01, Etc

@ejdelmonico Can you do comparisons on strings?

Like if (3 > 1.2839)

jpeterson579 started a new conversation Data Type For All Numbers. Ex: 2, 3.3, -2.890, 01, Etc

Trying to create my database but I cant figure out what data type to label a specific field in my migration.

I want the field to store numbers like 2, 3.3, -2.890, 01, etc... However, I dont want to enforce every number must have a certain amount of decimal places.

Any thoughts?

05 Nov
5 months ago

jpeterson579 left a reply on Get Average Review For Reviews Model Within Model...?

@cronix So since $products is going to return 10 random products how do I attach just the average review?

If I eager load my reviews model that is going to load every review in the view and I don't want that. I just want the avg number...

jpeterson579 left a reply on Get Average Review For Reviews Model Within Model...?

@staudenmeir So in my controller I use

public function homepage()
{
    $products = Product::inRandomOrder()->with('firstPhoto', 'avgReviewRating')->take(10)->get();
    return view('homepage', compact('products'));
}

jpeterson579 started a new conversation Get Average Review For Reviews Model Within Model...?

Hi All,

I am trying to calculate the average rating in my product model however getting the following error. No idea what is going on as this seems like it should work...

Call to a member function addEagerConstraints() on float

Product Model

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


public function avgReviewRating()
{
    return $this->reviews()->avg('rating');
}
29 Oct
5 months ago

jpeterson579 left a reply on Query Db Array Field From Form Multi-checkbox Array?

Added

->where(function ($query) use($power_requirement) {
    for ($i = 0; $i < count($power_requirement ); $i++){
          $query->where('power_requirement', 'like',  '%' . $power_requirement [$i] .'%');
    }  
})

Seems to do the trick

jpeterson579 started a new conversation Query Db Array Field From Form Multi-checkbox Array?

I can't wrap my mind around how this would be done or if its even the right way to go about it.

I have a database field called power that can have multiple values in it. Ex: Solar,Battery,Line So what I need to do if query the database based off of which checkboxes a user submits.

Form

<form class="productcomparison">
    <div>
        <p>Size/Width</p>
        Width Min <input name="width_min" value="">
        Width Max <input name="width_max" value=""><br>
    </div>
    <div>
        <p>Power Requirement</p>
        <input type="checkbox" name="chk_group[]" value="Solar" />Solar<br />
        <input type="checkbox" name="chk_group[]" value="Battery" />Battery<br />
        <input type="checkbox" name="chk_group[]" value="Rechargeable" />Rechargeable<br />
        <input type="checkbox" name="chk_group[]" value="Line" />Line<br />
    </div>
    <input name="submit" type="submit" value="Submit">
</form>

Controller.php

public function compare(Request $request)
{
    // 
    $req_width_min = $request->input('width_min'); 
    $req_width_max = $request->input('width_max');
    $power = $request->input('chk_group'); 
    
    $products = Product_Comparison::where('width_min', '<=', $req_width_min)
                                    ->whereRaw('width_max >= ' . $req_width_max)
                                    ->orderBy('created_at', 'asc')
                                    ->get();
    
    // Return Results to API
    return $request;
}
24 Oct
5 months ago

jpeterson579 left a reply on Get AVG From HasMany Relation Field?

Is it possible to get the avg inside the model so you're not loading 1000 reviews in the view?

22 Oct
6 months ago

jpeterson579 started a new conversation How To Simplify Script On Form Selection Results.

Hi All,

I'm wondering if there is a better way to simplify the following form script. What I don't want to have to do is duplicate the same long script for every single product 1 through 6.

Any advice on how this can be done?

<h3>Connection</h3>
<select name="connectionSelectionBox" id="connectionSelectionBox">
    <option value="any">Any</option>
    <option value="wired">Wired</option>
    <option value="wireless">Wireless (Battery powered)</option>
</select>

<h3>Voltage</h3>
<select name="voltageSelectionBox" id="voltageSelectionBox">
    <option value="any">Any</option>
    <option value="lowvoltage">Low Voltage (12-24V DC)</option>
    <option value="linevoltage">Line Voltage (120V AC)</option>
</select>

<h3>Product</h3>
<select name="productSelectionBox" id="productSelectionBox">
    <option value="product1">Product 1</option>
    <option value="product2">Product 2</option>
    <option value="product3">Product 3</option>
    <option value="product4">Product 4</option>
    <option value="product5">Product 5</option>
    <option value="product6">Product 6</option>
    <option value="product7">Product 7</option>
    <option value="product8">Product 8</option>
</select>

<div id="product1" class="result" data-motor-voltage="lowvoltage" data-motor-connection="wireless"></div>
<div id="product2" class="result" data-motor-voltage="lowvoltage" data-motor-connection="wireless"></div>
<div id="product3" class="result" data-motor-voltage="linevoltage" data-motor-connection="wireless"></div>
<div id="product4" class="result" data-motor-voltage="lowvoltage" data-motor-connection="wired"></div>
<div id="product5" class="result" data-motor-voltage="linevoltage" data-motor-connection="wired"></div>
<div id="product6" class="result" data-motor-voltage="lowvoltage" data-motor-connection="wired"></div>
<div id="product7" class="result" data-motor-voltage="linevoltage" data-motor-connection="wired"></div>

<script>
    if ($('select[name=modelSelectionBox]').val() == "product1") {                                                          
        $('.result').hide();
        if ($('select[name=voltageSelectionBox]').val() == "any" && $('select[name=connectionSelectionBox]').val() == "wired") 
        {
            $('.product1').show();
        }
        if ($('select[name=voltageSelectionBox]').val() == "lowvoltage" && $('select[name=connectionSelectionBox]').val() == "wired") 
        {
            $('.product1').show();
        }
        if ($('select[name=voltageSelectionBox]').val() == "linevoltage" && $('select[name=connectionSelectionBox]').val() == "wired") 
        {
            $('.product1').show();
        }
        if ($('select[name=voltageSelectionBox]').val() == "any" && $('select[name=connectionSelectionBox]').val() == "wireless") 
        {
            $('.product1').hide();
        }
        if ($('select[name=voltageSelectionBox]').val() == "lowvoltage" && $('select[name=connectionSelectionBox]').val() == "wireless") 
        {
            $('.product1').hide();
        }
        if ($('select[name=voltageSelectionBox]').val() == "linevoltage" && $('select[name=connectionSelectionBox]').val() == "wireless") 
        {
            $('.product1').hide();
        }
        if ($('select[name=voltageSelectionBox]').val() == "lowvoltage" && $('select[name=connectionSelectionBox]').val() == "any") 
        {
            $('.product').show();
        }
        if ($('select[name=voltageSelectionBox]').val() == "linevoltage" && $('select[name=connectionSelectionBox]').val() == "any") 
        {
            $('.product1').hide();
        }
    } 
</script>
16 Oct
6 months ago

jpeterson579 started a new conversation How Much Eager Loading Is Too Much?

Wonder how much eager loading is too much? For example eager loading 3 levels down? What if this result pulls in 200 records all of which will have the relations inside of relations inside of relations...

$reservations = Reservation::where('customer_id', Auth::user()->id)->with('trip', 'trip.company', 'trip.company.terms')->get();
15 Oct
6 months ago

jpeterson579 left a reply on How To Query Database Rows For 2 User Ids That Also Share Same Thread Id?

Thread Model

public function participants()
{
    return $this->hasMany(Models::classname(Participant::class), 'thread_id', 'id');
}

public function users()
{
    return $this->belongsToMany(Models::classname('User'),       
Models::table('participants'), 'thread_id', 'user_id');
}

public function scopeBetween(Builder $query, array $participants)
{
    return $query->whereHas('participants', function (Builder $q) use ($participants) {
        $q->whereIn('user_id', $participants)
            ->select($this->getConnection()->raw('DISTINCT(thread_id)'))
            ->groupBy('thread_id')
            ->havingRaw('COUNT(thread_id)=' . count($participants));
    });
}

Participant Model

public function thread()
    {
    return $this->belongsTo(Models::classname(Thread::class), 'thread_id', 'id');
    }
    
    public function user()
    {
    return $this->belongsTo(Models::user(), 'user_id');
    }

jpeterson579 left a reply on How To Query Database Rows For 2 User Ids That Also Share Same Thread Id?

Participants Migration

        $table->increments('id');
        $table->integer('thread_id')->unsigned();
        $table->integer('user_id')->unsigned();
        $table->timestamp('last_read')->nullable();
        $table->timestamps();

jpeterson579 started a new conversation How To Query Database Rows For 2 User Ids That Also Share Same Thread Id?

I am struggling to wrap my mind around this. I want to return the $thread->id that these 2 users are participating in.

    $teacher_id = 1;
    $user_id = Auth::user()->id;
    $thread = DB::table('participants')->whereIn('user_id', [$teacher_id, $user_id])->get();
01 Oct
6 months ago

jpeterson579 started a new conversation Can Laravel Cashier Handle Multiple One Time Payments?

Can laravel cashier handle one time payments? Like for an ecommerce type of store? But you only purchase 1 product at a time?

11 Sep
7 months ago

jpeterson579 started a new conversation How To Allow Users To Upload Videos? Intervention Image But For Video?

Hi all,

I am looking for some advice on how to safely allow users to upload videos to my website.

Once they upload them, how would I be able to resize, change file to mp4, etc.?

Is there anything that does what Intervention Images does but for video?

Thank you!

09 Aug
8 months ago

jpeterson579 left a reply on Query Model Based On Variable Input That Can Be Null?

@36864 Thank you for the response. So this could work but I have 2 questions.

  1. $color will only return true or false inside the when function so how do i get the actual value from the form.

  2. Will this work with multiple when statement and go from one to the next to the next?

jpeterson579 started a new conversation Query Model Based On Variable Input That Can Be Null?

I am trying to search my products table with the following form. I want people to have the option to be able to just search by 1 filter or all filter options.

The issue I am running into is that then sometimes field values can/will be null OR equal to 'any'.

So how can I run a query where if 'any' is selected, it will return all results for that filter, and if null is the value it will do the same?

My current code below.

Form

<form method="GET" action="/">
    <input type="text" name="Search Location">
    <input type="text" name="Search Keywords">
    <select class="wide" name="color">
        <option value="any">Any Color</option>  
        <option value="red">Red</option>
        <option value="blue">Blue</option>
        <option value="green">Green</option>
    </select>
    <select class="wide" name="price">
        <option value="any">Any Price</option>  
        <option value="0 - ">0 - </option>
        <option value=" - "> - </option>
        <option value=" - "> - </option>
    </select>
</form>

Controller

public function search(Request $request)
{
    $location = $request->search_location;
    $keywords = $request->search_keywords;
    $color = $request->color;
    $price = $request->price;
    
    $products = Product::where('location', $location)
                 ->where('keywords', $keywords)
                 ->where('color', $color)
                 ->where('price', $price)
                 ->get();       
    
    dd($products);
}
31 May
10 months ago

jpeterson579 started a new conversation Eager Loading Only Last 10 Records?

How can I run the following code but instead of loading all news items associated with a company only load the most recent 10?

$companies = Company::with('news', 'jobs')->get();
29 May
10 months ago

jpeterson579 left a reply on How To Merge Duplicate/similar Records In An Object?

Got it,

Used

DB::raw('SUM(count) as "counts"')

jpeterson579 left a reply on How To Merge Duplicate/similar Records In An Object?

Thanks @Cronix

I used

$tweets = Tweet::where('company_id', $company->id)
                        ->groupBy('date')
                        ->get(array(
                            DB::raw('Date(date) as date'),
                            DB::raw('count(*) as "count"')
                        ));
return $tweets;

However, instead of adding the 2 numbers, it is just counting the number of records where the date was the same. see below.

[ { "date": "2018-05-11", "count": 2 }, { "date": "2018-05-12", "count": 2 }, { "date": "2018-05-13", "count": 2 }, { "date": "2018-05-14", "count": 2 }, { "date": "2018-05-15", "count": 2 }, { "date": "2018-05-16", "count": 2 }, { "date": "2018-05-17", "count": 2 }, { "date": "2018-05-18", "count": 2 }, {

jpeterson579 started a new conversation How To Merge Duplicate/similar Records In An Object?

Hi All,

I have the following code which gives me an object. However, there are duplicate dates with different count numbers. I wanted to know if there is a way to merge the values in this object that share the same date and then add the count fields for those dates together?

Code

foreach ($company->tweets as $t)
{
    $date = $t->date;
    if ($date == $t->date)
    print $t->date . ' - ' . $t->count . '<br>';
}

Result

2018-05-11 - 1177
2018-05-11 - 3493
2018-05-12 - 19538
2018-05-12 - 5556
2018-05-13 - 17683
2018-05-13 - 5884
2018-05-14 - 9417
2018-05-14 - 19714
2018-05-15 - 29853
2018-05-15 - 22965
2018-05-16 - 21725
2018-05-16 - 21733
2018-05-17 - 10998
2018-05-17 - 21829
2018-05-18 - 10333
2018-05-18 - 4763
2018-05-21 - 523
2018-05-21 - 2523
2018-05-22 - 7325
2018-05-22 - 10797
2018-05-23 - 11922
2018-05-23 - 6968

Thank you for the help!

11 May
11 months ago

jpeterson579 left a reply on Continue Running Artisan Command Even After Terminal Is Closed?

OK for the second part I ran

nohup php artisan queue:work --daemon &

This and then CTRL A + D to log out the terminal and both are still running.

Now the only thing I need to know is how I can stop both artisan commands?

jpeterson579 left a reply on Continue Running Artisan Command Even After Terminal Is Closed?

@thyrosis Thank you part of the way there I was able to run my artisan command and then press ctrl a + d to log out of terminal but keep the command running.

So what if I want to log back into terminal and turn off the artisan command? How would that be done?

Also I am running

php artisan queue:work

to process the data from the above command, however, it wont let me ctrl a + d out of that...?

jpeterson579 left a reply on Continue Running Artisan Command Even After Terminal Is Closed?

I was thinking about that however the artisan command is a continues stream, its not like an API i can hit every 5minutes.

And if its a continuous stream, how would running this artisan command 5 times effect it. Would i then have 5 streams?

jpeterson579 started a new conversation Continue Running Artisan Command Even After Terminal Is Closed?

Hi all,

I have a custom artisan command

php artisan connect_to_custom_api

that I enter once and it runs indefinitely grabbing in info from an api. However, every time I exit the terminal it stops.

Is there a way to make this run even after the terminal is closed?

Also, if so, how would I get it to stop if I ever wanted to?

Thank you!

06 Mar
1 year ago

jpeterson579 left a reply on HasMany Or Polymorphic Relationship For News Feed?

@hhda

I know I can eager load the info for each person however if I did it that way, how would I then be able to display the events, posts, and ratings models in a single feed sorted by the most recent record created?

event rating event rating rating post event

etc...

05 Mar
1 year ago

jpeterson579 started a new conversation HasMany Or Polymorphic Relationship For New Feed?

I still can't seem to wrap my head around how to structure this.

My end goal is for a user to be able to see a single feed of all the ratings, events, posts, that other users they are following have posted.

My models look like this.

    public function ratings()
{
    return $this->hasMany(App\Rating);
}
public function events()
{
    return $this->hasMany('App\Event');
}
public function posts()
{
    return $this->hasMany('App\Event');
}
//  Realtion grab users that user is following  
public function following()
{
    return $this->belongsToMany(User::class, 'following')->withTimestamps();
}
02 Mar
1 year ago

jpeterson579 left a reply on What Is This Model Relationship? User Can Follow Other Uses But Also Follow Companies?

@Drfraker

I set up a polymorphic relationship as so but am not getting any results...

Follow Model

/** * The table associated with the model. * * @var string * */ protected $table = 'following';

/**
*       This belongs to a user
*/
public function user()
{
    return $this->belongsTo('App\User');
} 

/**
*   
*/ 
public function followable()
{
    return $this->morphTo();
}

User Model

public function followers()
{
    return $this->morphMany('App\Follow', 'followable');
}

Business Model

 public function followers()
{
    return $this->morphMany('App\Follow', 'followable');
}

Controller

$user = User::find(1);      
dd($user->followers);

My 'following' table: id user_id followable_id followable_type created_at updated_at

Anyhow by dd is returning Collection {#581 ▼ #items: [] }

Which should not be true as I have multiple records in the following table for user 1

01 Mar
1 year ago

jpeterson579 left a reply on Sort Eloquent Query By Model Relationship

Hmm, I think this would work but are you ordering the ratings.like_votes here?

To order the ratings by how many like_votes it has wouldn't it be something like

$post = Post::where('id', $post_id)->with(['ratings' => function ($query) 
{
    $query->orderBy($query.like_votes->count(), 'desc');
}, 
'ratings.user', 'ratings.like_votes'])->firstOrFail();

jpeterson579 started a new conversation Sort Eloquent Query By Model Relationship

So I have the following query

$post = Post::where('id', $post_id)->with('ratings', 'ratings.user', 'ratings.like_votes')->firstOrFail();

How do I sort ratings by ratings with the most like_votes?

27 Feb
1 year ago

jpeterson579 started a new conversation What Is This Model Relationship? User Can Follow Other Uses But Also Follow Companies?

Hi there, could someone point me in right direction for how to structure my model?

Currently, I have

User

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

public function following()
{
    return $this->belongsToMany(Business::class, 'following')->withTimestamps(); 
}

Business

public function user() {
    return $this->belongsTo('App\User');
}

Follow

class Follow extends Model
{
     protected $table = 'following';
 }

Basically, I want users to be able to follow other users but all follow businesses and then pull up all things they are following in a single feed.

20 Feb
1 year ago

jpeterson579 started a new conversation Making Signup Usernames Unique And Url Friendly

Hi all, cant wrap my head around how this is typically done.

I want people to be able to register with a unique username and then the link to their public profile is something like https://www.domain.com/username

The issue i cant wrap my mind around is how to make them not enter spaces or special characters that dont work in urls.

Thoughts?

14 Nov
1 year ago

jpeterson579 left a reply on How To Allow User To Do A Search Which Returns A Route With The Search Query In It?

@Snapey

So using GET will give me a url like this

http://localhost:8888/search?_token=YbhH1RM56npIRBk5TSpf41fLOj83a6VDQlpdRLNS&author=JK+Rolling&all=on

How do I get rid of the token in this url? I want the form to require a token but dont want to to display on the url

jpeterson579 left a reply on How To Allow User To Do A Search Which Returns A Route With The Search Query In It?

@Snapey If a user wants to share a link to his results. The person he shared it with would not have to do the search part again but could follow the link.

Also for SEO and search engines. If these pages were linked to, search engines could easily crawl the results for specific queries since there is an actual url associated with it...

Does that make sense or am I thinking about this all wrong?

jpeterson579 started a new conversation How To Allow User To Do A Search Which Returns A Route With The Search Query In It?

Hi All!

I have a search box that allows users to input a book name and then gives them a list of books that match that query.

What I want to be able to do is after the search form is submitted it will direct them to a route:

search/book/{searchQuery}

How could I do this?

Furthermore, what if the user searches something that is multiple words? Or special characters? Won't this break the URL since there will be spaces or foreign characters in it now? How can I combat this?

12 Oct
1 year ago

jpeterson579 left a reply on Laravel Api Post Request Redirect Back To External Url

@topvillas

Hmm actually not using ajax to submit the form. Is that the best way to accomplish this? And does that solve the issue?

jpeterson579 left a reply on Laravel Api Post Request Redirect Back To External Url

@tykus when I submit using

return redirect()->back();

and

return back();

I get the following error

Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException
No message




/var/www/myapi/vendor/laravel/framework/src/Illuminate/Routing/RouteCollection.php
    if ($request->method() == 'OPTIONS') {
        return (new Route('OPTIONS', $request->path(), function () use ($methods) {
            return new Response('', 200, ['Allow' => implode(',', $methods)]);
        }))->bind($request);
    }

    $this->methodNotAllowed($methods);
}

/**
 * Throw a method not allowed HTTP exception.
 *
 * @param  array  $others
 * @return void
 *
 * @throws \Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException
 */
protected function methodNotAllowed(array $others)
{
    throw new MethodNotAllowedHttpException($others);
}

/**
 * Get routes from the collection by method.
 *
 * @param  string|null  $method
 * @return array
 */
public function get($method = null)
{
    return is_null($method) ? $this->getRoutes() : Arr::get($this->routes, $method, []);

jpeterson579 started a new conversation Laravel Api Post Request Redirect Back To External Url

Hi all!

I am trying to create an api that allows me to make an contact form on another site and then send a post request to my api url that send stores the info in a database and generates an email.

The problem i am having is that when the person submits to form, they go to the api's url and stay there instead of remaining on the external website with a success message.

How can I fix this?

controller

/*
*      API Landing Page Email Form
*/
public function lpContact(Request $request)
{
    
    Mail::send('email.lpform', ['request' => $request], function ($m) use ($request) {
        $m->from('[email protected]', 'User Name');
        $m->to('[email protected]', 'John')->subject('Inquiry from Landing Page' );
    });
    // Return back to external landing page with success data
return 'Success, Your message has been sent.';

}
12 Sep
1 year ago

jpeterson579 left a reply on Always Free Plan (no Trial), But With Possibility To Subscribe To Paid Plans

Cant you just do

Spark::useStripe()->noCardUpFront()
05 Sep
1 year ago

jpeterson579 left a reply on None Of My Routes Work Except For The '/' - New Laravel 5.5 Install

Sorry not following @papa

index.php is in the public folder so how would this path work regardless?

jpeterson579 started a new conversation None Of My Routes Work Except For The '/' - New Laravel 5.5 Install

Just set up a new Ubuntu server running Nginx and thought everything was working fine. When I go to my domain, the laravel welcome page come up fine.

However, I created my first route to load a basic view and I get a 404 Not Found error.

Need some advice on what could be going on and how to fix.

25 Aug
1 year ago

jpeterson579 started a new conversation How To Run Vue.js Script After Page And All Other Scripts Have Fully Loaded?

I am using vue.js to create a google map with pins on it, however I am finding that the map only loads 50% of the time. I find myself having to refresh the page a couple of times until it load.

I am thinking that this is because vue.js is trying to create the map before the google maps api has fully loaded.

Currently this script is in mounted() {} hook.

Is there a way to run this script only after the google maps api scripts have fully loaded?

jpeterson579 left a reply on Laravel 4.2 No 'Access-Control-Allow-Origin' Header

Sorry @martinbean had a typo in my question. Made the fix and still get same error.

jpeterson579 started a new conversation Laravel 4.2 No 'Access-Control-Allow-Origin' Header

I can't seem to figure this out. I am posting to my API to return some data but I'm getting the error:

XMLHttpRequest cannot load https://domain.com/api. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://www.somfysystems.com' is therefore not allowed access.

It's funny because when I do a get request to the API it works fine but for some reason the post request won't work.

My code:

return response($data)->header('Access-Control-Allow-Origin', 'https://www.domain.com')->header('Access-Control-Allow-Methods', 'GET, POST, OPTIONS');
09 Aug
1 year ago

jpeterson579 left a reply on Vue.js Axios How To Get Access To Posted Data In Controller?

Thanks, @lars6 that function stopped my vue.js code from running somehow.

However, I did fix this by changing my controller to:

use App\Http\Requests;

    public function specTool(Request $request)
{
    return $request->application;
}

jpeterson579 started a new conversation Vue.js Axios How To Get Access To Posted Data In Controller?

I've been trying to figure this out for the past 2 hours and have hit a road block. I'm using vue.js and axios to post to an apicontroller I have however once there I am unable to grab the individual pieces of data such as powerSource.

See code below but I thought I would have been able to do something as easy as return $object->application in my controller and it's throwing an error.

Vue.js File

new Vue({
 el: '#app',
 data:{
   model:{
        application:'Radio',
    powerSource:'AC',
    technology:'Satelite',
    soundLevel:'50',
   },
   solution:[],
 },
 methods: {
   onComplete: function(){
    axios.post('https://mysite.com/api/spectool', this.model).then(response => {
        this.solution = response.data;
        console.log(this.solution);
    });
   },
  }
})

ApiController

public function specTool()
{
    $input = Input::all();
    $object = $input;
    return $object->application;
}
28 Jul
1 year ago

jpeterson579 started a new conversation Filter Data By Checkboxes Does Not Work When Selected In Reverse Order?

Hi all, I am trying to create a filter that goes through and only shows results based off of what check boxes are selected. However, this only works if the boxes are selected in the correct order. For example, if I select blinds and curtains it works but if you select that in the reverse order it does not show any results...

Anyone have an idea?

  <!-- Checkboxes -->
<div class="row">
    <div class="col-md-6">
        <input id="check-1" type="checkbox" name="check" value="all applications" v-model="checkedapps" class="all" checked="checked">
        <label for="check-1">All Categories</label>

        <input id="check-2" type="checkbox" name="check" value="blinds" v-model="checkedapps">
        <label for="check-2">Blinds</label>

        <input id="check-3" type="checkbox" name="check" value="shades" v-model="checkedapps">
        <label for="check-3">Shades</label>
        
        <input id="check-4" type="checkbox" name="check" value="curtains" v-model="checkedapps">
        <label for="check-4">Curtains</label>
        
        <input id="check-5" type="checkbox" name="check" value="projection" v-model="checkedapps">
        <label for="check-5">Projection Screens</label>
    </div>  

    <div class="col-md-6">
        <input id="check-6" type="checkbox" name="check" value="awnings" v-model="checkedapps">
        <label for="check-6">Awnings</label>

        <input id="check-7" type="checkbox" name="check" value="pergolas" v-model="checkedapps">
        <label for="check-7">Pergola</label>    

        <input id="check-8" type="checkbox" name="check" value="screens" v-model="checkedapps">
        <label for="check-8">Exterior Screens</label>
        
        <input id="check-9" type="checkbox" name="check" value="shutters" v-model="checkedapps">
        <label for="check-9">Rolling Shutters</label>
    </div>
</div>
<div v-for="fab in filteredItems" class="col-lg-12 col-md-12">
    {{ fab.name }}
</div>

vue.js

var vm = new Vue({
    el: '#app',

    data: {
        locations: [ 
                { "id": "1", "name": "Product 1", "options": "blinds,shades,curtains,projection,commercial"}, 

{ "id": "2", "name": "Product 2", "options": "blinds,curtains,shutters,screens,awnings" } ], checkedapps: [], message: 'Hello Vue!', },

    computed: {
        filteredItems() {
            return this.locations.filter(fab => {
                return fab.options.indexOf(this.checkedapps) > -1
            })
        }
    },
    
})
11 Jul
1 year ago

jpeterson579 left a reply on How To Eager Loading Other Model From DB::Select() Query?

@jlrdw

Business Model

// A business has many ratings

public function ratings() { return $this->hasMany(Rating::class); }

Ratings Model

// A rating belong to a business
    public function business()
{
    return $this->belongsTo(Business::class);
}