Snapey

Snapey

at Novate / Microlise

Mansfield

Hire Me

Member Since 4 Years Ago

Experience Points 1,117,815
Experience
Level
Lessons Completed 1001
Lessons
Completed
Best Reply Awards 1596
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.

17 Jan
16 hours ago

Snapey left a reply on Do Modified Collections Maintain The Same Keys As Original?

Correct myself. If you use filter, your collection will gain keys;

>>> $items
=> Illuminate\Support\Collection {#2964
     all: [
       [
         "id" => 1,
         "size" => 18,
         "qty" => 25,
       ],
       [
         "id" => 2,
         "size" => 18,
         "qty" => 500,
       ],
       [
         "id" => 3,
         "size" => 18,
         "qty" => 50,
       ],
       [
         "id" => 4,
         "size" => 24,
         "qty" => 15,
       ],
     ],
   }
>>>

>>> $items2 = $items->filter(function($item){
             return $item['id']==2||$item['id']==4;
    });
=> Illuminate\Support\Collection {#2925
     all: [
       1 => [
         "id" => 2,
         "size" => 18,
         "qty" => 500,
       ],
       3 => [
         "id" => 4,
         "size" => 24,
         "qty" => 15,
       ],
     ],
   }
>>>

Snapey left a reply on Do Modified Collections Maintain The Same Keys As Original?

No, your data is a simple array, those 2 => and 3 => are annotations in the var_dump only

Snapey left a reply on Checking Two Different Models And Returning The Results

And don't forget to avoid n+1 by eager loading bids in the controller

Snapey left a reply on Json Validation Failed For Valid Json

You can use jsoneditoronline.org to both pretty format and validate your data.

{
  "specification": [
    {
      "type": [
        {
          "type": "Smartphone , Phablet , Notch Phone , Camera Phone , Selfie Phone",
          "shape": "Bar"
        }
      ],
      "basic": [
        {
          "os": "Smartphone , Phablet , Notch Phone , Camera Phone , Selfie Phone",
          "Sim": "Bar"
        }
      ]
    }
  ]
}

Your data is valid format but badly structured.

In your validation 'specification' is the name of the http attribute you are validating and not part of your data

16 Jan
1 day ago

Snapey left a reply on Auth()->user() Does Not Have Methods In User Model(laravel-ide-helper)

I dont think you can do that because ypur IDE has no idea that user() helper relates to the User class

Snapey left a reply on Laravel Get Count Items By Status

$shops = Shop::where('user_id', Auth::user()->id)->byRating()->get();

Snapey left a reply on BelongsToMany For More Than 2 Foreign Keys?

There is no problem or complication using three foreign kets in one model

BelongsToMany is only for use where the 'many' applies in both directions, ie a single event would need to belong to multiple corporations- i dont see that from your description

15 Jan
2 days ago

Snapey left a reply on Undefined Variable Error Laravel 5.5

why not tell us which line has the error?

Snapey left a reply on Try To Show Last Selected Option In Foreach

If you amend the relationship

    public function times()
    {
        return $this->hasMany('App\Time')->latest();
    }

then the times will be sorted and you can pick ->first() to get the latest entry

Snapey left a reply on Laravel Custom Form Request Get Id

use the null coalesce operator

$id = $this->shop->id ?? null;

Snapey left a reply on Return User To Page They Logged In From

@jlrdw. Its not an ajax call

if they are not logged in it pushed them to the login screen.

Snapey left a reply on Show New And Old Attributes

@aurawindsurfing Its correct that it would only be in one request cycle but I wanted to ensure it was not confused with old data in the request.

The model will continue to show changed fields until it is refreshed either as a result of a new query or an explicit fresh() call, or of course in a new request cycle.

Snapey left a reply on Return User To Page They Logged In From

@mac03733 I dont follow. If your app crashes its because of a coding error. A redirect should never cause a crash unless you end up in a redirect loop.

Snapey left a reply on How To Redirect Page When Page Has An Internal Error Laravel

Laravel does this for you anyway if debug=false

14 Jan
3 days ago

Snapey left a reply on Try To Show Last Selected Option In Foreach

ignoring the store method, what should the form show if the user reloads the page?

Snapey left a reply on Changes To App.blade.php Not Rendering

and obviously that view has to @extend the spark app.blade.php

Snapey left a reply on Confusing Query.

I would have a Play model, this would hold the stream, the station and the song as well as the play time.

It may help you think about the representation as its own model rather than an elaborate pivot table

Snapey left a reply on Single Page Design & Laravel Form

so if it is /#contact then just put that in the redirect

return redirect('/#contact');

Snapey left a reply on Single Page Design & Laravel Form

Why would you change the route? What route are you using to show the page?

It still has a route even if it is an SPA

How are you changing the URL when switching pages in the front-end?

Snapey left a reply on Laravel API Resources Extremely Slow

If you don't eager load the relations then line such as this;

'manager' => isset($this->user->manager) ? $this->user->manager->fullName : null

will do a database query for every row in your user table (eg 870 times)

In addition, all that data has to be loaded and assembled in memory which gives you a big footprint for the application and might cause scalability problems.

Even though you are writing this as an API, I would still install Laravel debugbar and test your code in a simple browser call so that you can see the debugbar output. It will tell you how long each database query takes and how much memory.

Snapey left a reply on Counting Records In Collection

Please mark it as solved

Snapey left a reply on Single Page Design & Laravel Form

return back();

or

return redirect(route('contact-form'); ... or whatever you name the route

eg

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

Snapey left a reply on Trying To Make A Recipe App, Including Beer

All recipes have a process consisting of multiple steps. Its not sufficient to just have ingredients.

I don't see how beer represents a unique challenge?

Snapey left a reply on Problem In Uploading Laravel Application.

Do you have ssh access to the server?

Snapey left a reply on Show New And Old Attributes

@aurawindsurfing it shows you model changes. Not much to do with requests.

Snapey left a reply on Show New And Old Attributes

$model->getOriginal()

Snapey left a reply on Problem In Uploading Laravel Application.

run a mile if the provider can only give unsupported php versions.

Snapey left a reply on Return Blade View As String

Close. Try

View::make('template',['key' =>'value'])->render()
13 Jan
4 days ago

Snapey left a reply on Add Array=>value To Multi Dimensional Key Function

It would help if we knew a) what you were trying to do and b) what your data looks like.

At the moment you are just saying, I'm using this code and its not right.

It might be obvious to you as you are in it, but just look back at what you posted?

Did you try Laravel helper array_flatten() ?

Snapey left a reply on Manual Auth Login

did you change the authentication config file?

Snapey left a reply on Laravel Eloqouent Handling Users With Different Fields/data

Is it such a problem to have empty columns?

Perhaps think about different Profile classes that use polymorphic relationships to a User model

Snapey left a reply on Using Variables In Controllers

You are not making sense.

I am get a form working.

Where's the form?

It has multiple sliders which are pulled from a database table so teh id would be different for each slider depending on which are picked.

How will the user 'pick' a slider?

Snapey left a reply on Using Variables In Controllers

same question here... picked how?

Snapey left a reply on Pagination For Search Results Laravel 5.7

Probably change last where to orWhere

Snapey left a reply on Laravel Relationship : One ForeignKey For Several LocalKey Relationship

no, I think this is easiest. You could get users by using;

$matchUsers = User::where('id',$match->playerOne_id)
            ->orWhere('id,$match->playertwo_id)
            ->get();

but then $matchUsers would be its own collection and not a nested relationship to $match

Snapey left a reply on Laravel Relationship : One ForeignKey For Several LocalKey Relationship


class Match extends Model
{
    protected $table = 'matchs';

    public $primaryKey = 'id';

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

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

Check the capitals in your relations. In the table information in the question you have playerOne_id and playertwo_id (inconsistent) . Check the column names in my proposed model code exactly matches the table design

Snapey left a reply on Making Form Dropdown: DRY And Validate?

If you want an array of items that will only change through code changes then you can do this with a simple config file. For instance, in your example of states, make a file states.php in the config folder and then put in it;

<?php

return [

    'NY','NJ','CA'....
];

Then in a view,

@foreach(config('states') as $state)
    <option>{{ $state }}</option>
@endforeach

and in validation use the in rule and pass the config element.

But, if you want a user to be able to change these lists of values then a user interface could be built to modify the spatie value store. This is where there are maybe a list of choices that the user decides.

Suppose you were building a HR system, you might start with a list of 'types' such as 'Manager', 'Supervisor', 'Developer' etc has a get them started type list. But then the user of the system wants to add new job types. They should be able to do this without coming to you to edit the code. You could create a table for this, or you could store it in the valuestore.

If you hold that valuestore in code then when you deploy an updated version of the application you could easily overwrite the user's modified list with your base list.

This is why I mentioned seeding or Migrations.

Migrations are just a script that runs only when you ask for it, and hopefully not twice. Just as you might push rows into the database after building the tables, you could do the same for valuestore.

A migration created like php artisan make:migration == create_job_types --create=whatever will contain;

<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateJobTypes extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('whatever', function (Blueprint $table) {
            $table->increments('id');
            $table->timestamps();
        });
    }

You can put whatever code you like in the up() and down() methods, eg

    public function up()
    {

    $valuestore = Valuestore::make($pathToFile);

        $valuestore->put(['jobtypes' => [
            'Director',
            'Manager',
            'Supervisor',
            'Developer',
            ],
    ]);

    }
    

The benefit of this is that if you redeploy to a new server, you can run php artisan migrate:fresh and have the value store initiated.

Snapey left a reply on Laravel Relationship : One ForeignKey For Several LocalKey Relationship

A match does not hasMany player 1 - it only has one. The match belongsTo player 1

The match also belongsTo player 2

If you load the relations like this;

$match = Match::with(['playerOne','playerTwo'])->find(1);

then you will have $match->playerOne and $match->playerTwo in your view and not an array of users

Snapey left a reply on Removing Duplication Date In Blade View

You can show the tabular output better by putting 3 backticks ``` on a line before and after

Can you include your blade code?

Snapey left a reply on Eager Loading Returning False Relation Data

This now looks like a straight forward relation, and not what you were talking about before ?

Anyway, to answer your question, aren't you dealing with the product anyway ?

Im lacking context to understand whats best

Snapey left a reply on How To Track Links In Webapps ?

one way is with google analytics, as you may already know https://support.google.com/analytics/answer/1136920?hl=en

Otherwise, two solutions that come to mind.

  1. Javascript. listen for the click event on the link and fire an ajax call to your server to say the user clicked. After firing your ajax call, allow the click to propogate tothe default action.

  2. Route all links through your server. Prefix the link with your own route. Eg instead of a link direct to the other site, itsa link to your site with the external link as a querystring (url encoded). The click will come to you and you can do a redirect to the real link.

Keep track of user clicks and dont count it if they already clicked.

12 Jan
5 days ago

Snapey left a reply on Show @click="" Only If IsAdmin() Is True Without Repeating Myself. Getting Syntax Error.

your error is because you have {{ inside {{ so the second pair are not evaluated as blade tags

Your post is confusing though. In your blade code @admin is outside the input element, but in the evaluated view, its inside the input. Your question therefore seems inconsistent

Snapey left a reply on Laravel Relationship Methods

Then I dont know what else you want to know