Tray2

Tray2

Member Since 4 Years Ago

Solna

Oracle Developer (PL/SQL, Forms & Apex) at Scania CV AB

Experience Points 132,470
Experience Level 27

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

23 Apr
1 day ago

Tray2 left a reply on Query Takes 10 Seconds If I Add OrderBy And Paginate

Look like there are a few full table scans in this one.

I suggest you do an explain plan and look for them. Add indexes where they are it might help. I would also see which part of the query that takes the most time and place that last.

22 Apr
2 days ago

Tray2 left a reply on PHP

Are you using blade or vanilla PHP?

Blade

@foreach($somethings as $something)
    {{ $something->field }}
@endforeach

Vanilla

<?php
 foreach($somethings as $something) {
    echo $something['field'];
}

Tray2 left a reply on Laravel

Do you have the proper permissions to your storage folder?

Tray2 left a reply on Eloquent Query That Sum Of Two Column Greater Than A Number

Transaction::whereRaw('plan_price - final_price >= 5');

Should work.

21 Apr
3 days ago

Tray2 left a reply on DB Update Not Working - Non-static Method Illuminate\Database\Eloquent\Model::update() Should Not Be Called Statically

Something like

$view = model::where('field', 'condition')->first()
$view->pageviews++;
$view->update();

Should work.

20 Apr
4 days ago

Tray2 left a reply on Why MySql Show Number Of Rows 2X After Adding Foreign Key

Not knowing anything about you code but I think you have two records in the machines table.

If so you are probably running a query similair to this one.

SELECT da.field, m.field
FROM device_alerts da,
            machines m;

That will give you two rows for each record in table.

To solve this you need to join the tables in your query.

SELECT da.field, m.field
FROM device_alerts da,
            machines m
WHERE da.machine_id = m.id;

Tray2 left a reply on View Reflecting HasOne And HasMany

What you call the controller is up to you but not all models needs controllers. I suggest however to follow the naming conventions in Laravel.

Model are named The same as the table but in singular ie posts table has a model named Post Controllers are named after the table, so posts table will become PostController or PostsController (singular or plural is optional here).

Tray2 left a reply on Display 4 Layers Of One To Many Relationships In A Single View

Not sure what you mean exactly but if you have the correct relationships set up you can do something like this

@foreach($forms as  $form)
  <a href="/forms/{{ $form->id }}">{{ $form->question }}</a><a href="/forms/{{$form->subsection_id }}">{{ $form->subsection->question }}</a>

@endforeach

Tray2 left a reply on View Reflecting HasOne And HasMany

If you have something like

public function index()
{
  $customers = Customer::all();
  return view('customer.index', compact('customers'); 
}

In your controller and

public function address()
{
  return $this->hasOne(CustomerAddress::class);
}

In your Customer model you can

{{ $customer->address->zip }}

In your view

Tray2 left a reply on Add Unique $table->unique Generates Error

There seems to be a limitation on how long the constraint name can be.

I haven't tried it but in most places it's possible to override the default naming so something like

$table->unique([], 'index_name');

might work.

16 Apr
1 week ago

Tray2 left a reply on Images Not Saving To Path When I Update My Database?

Are you uploading a new file? If so make sure you have set the form to multipart.

Do some poor man debugging by dd($request);too mke sure the file is passed.

Tray2 left a reply on Database Migrate From MySQL To Azure SQL

According to Microsoft the Azure SQL is basically the latest stable version of SQL Server so switching should not be that hard.

https://docs.microsoft.com/en-us/azure/sql-database/

You could probably get away with just changing your env file to use sql server.

https://barryvanveen.nl/blog/39-connect-to-mssql-database-from-php

Tray2 left a reply on Shared Web-host Displays My User's Root Directory?

Then you probably should check on how to set up a subdomain and how to reroute to it.

Tray2 left a reply on Shared Web-host Displays My User's Root Directory?

Sounds a bit like you hace problems with your document root. If you are running Apache check out .htaccessand how to reroute everything to your public folder.

https://stackoverflow.com/questions/23635746/htaccess-redirect-from-site-root-to-public-folder-hiding-public-in-url

Tray2 left a reply on Database Migrate From MySQL To Azure SQL

A quick search revieled this https://docs.microsoft.com/en-us/azure/app-service/containers/tutorial-php-mysql-app I hope that is something as to what you are looking for.

14 Apr
1 week ago

Tray2 left a reply on Should Eloquent Be In My Controller Or Model

A matter of style and or taste imho.

Simple queries like

$books = Book::all();

I would place in the controller but more complex 5+ lines or so I might consider moving to the model.

Since I try to keep my eloquent as simple as possible I move the more complex stuff into database views.

Tray2 left a reply on Including Views With Javascript Code

The serverside builds the page from your includes so a simple view source in your browser will give you everything.

13 Apr
1 week ago

Tray2 left a reply on Including Views With Javascript Code

Without any code it's a bit hard to see what goes wrong but you need to load the javascript last to make sure that all the elements that you use are in place.

12 Apr
1 week ago

Tray2 left a reply on Dealing With Huge Tables And Pagination

The first thing I'd do is add some indexes to those tables and I think you could shave of at least 50% of the time there. You can run explain plan to see where it uses full table access and add the indexes there. You will also probably see which part of the query takes most of the time and then you can put that last so you have the smallest possible selection to run it on.

I would also make sure that any carthesian products are removed since they are usually bad for performance.

11 Apr
1 week ago

Tray2 left a reply on Is There Anything In Laravel Natively That Can Give Ajax Like Functionality?

You need Javascript for that as far as I know.

10 Apr
2 weeks ago

Tray2 left a reply on Can I Omit PHP Docblocks If I Type Hint Parameters And Return Values?

Docblocks are optional and the same goes for typehints. You don't really need them but some argue that you always should use docblocks and or typehints and some argue against it.

It all comes up to personal preferences unless of course there is a standard at the company or project that says you should use one or both.

03 Apr
3 weeks ago

Tray2 left a reply on Comparing Factory To Eloquent Model

Do a ddon them both and you will probably see the problem.

I haven't tested it but when you make your settings you don't have an idand you don't have created_atand updated_at all of which you most likely have when you call $user->settings.

Tray2 left a reply on Where Do I Add My Normal Nginx Configuration?

On the individual server. The load balancer is only like a traffic cop deciding which road your request should take.

Tray2 left a reply on General Question: How Do I Identify Where My Error Has Originated?

The problem seems to be in your updateAdjustment method

Probably this line

DB::table('adjustments')->where([ ['fromPID','=',$chunks[$i][0]] , ['toPID','=',$chunks[$i][1]], 'on','=',$chunks[$i][2]], ['at','=',$chunks[$i][3]] ])->update(['status' => $chunks[$i][4]]);
01 Apr
3 weeks ago

Tray2 left a reply on Can Anyone Correct My Blade Syntax For Window.location='' Location?

<form action="" method="">
<button onclick="yourFunctionHere()" class="btn_back" name="btn_back">
</form>

Why use a button when it seems to be a normal link?

Tray2 left a reply on Remember The Owner Of An Uploaded File Without Force Him To Sign In?

Why not just ask them for their email when they upload the image?

Tray2 left a reply on Getting 500 Error JQuery

500 errors means that there is something wrong at the backend and not the frontend so show your controller code for that route.

Tray2 left a reply on Can Not Use Variable Outside Of If Statement

Like stated before you need to initiate $pushin the top of your function

public function getStuff(Request $request)
{
     $push = '';

     //your code here
}

Read about variable scopes

https://www.php.net/manual/en/language.variables.scope.php

29 Mar
3 weeks ago
28 Mar
3 weeks ago

Tray2 left a reply on DB Check For Not Taken Title If Not Current Id

$request->validate(['title' => 'unique:courses']);

Is how I would do it.

Tray2 left a reply on Reorder Columns Of A Table Where Sort_number Is Unique

You can temporarly disable the unique indexes SET UNIQUE_CHECKS=0;.

How often is this updated? If the answer is more than once a day I suggest that you remove the constraint from your table.

27 Mar
4 weeks ago

Tray2 left a reply on JavaScript Mouseenter And Mouseleave Fade Effects Glitchy.

It seems that the fade in is run at least twice instead of once and that might be the issue.

Tray2 left a reply on Mysql Index Key Not Provided When Not Limiting Query Result

SQL optimization is always tricky but usually moving the heaviest lifter (in this case the between) last usually helps a bit.

What you can try is to move older records to another table, let's say everything older than three months and then build check if the dates are in which table and build the query dynamically.

26 Mar
4 weeks ago

Tray2 left a reply on Mysql Index Key Not Provided When Not Limiting Query Result

Then it should use an index.

However I would move the between condition last since it probably gives the biggest span just to test.

25 Mar
4 weeks ago

Tray2 left a reply on Mysql Index Key Not Provided When Not Limiting Query Result

Unless there is a huge difference in execution times I wouldn't worry about it since the MySQL parser is probably smarter than both you and me. It will choose the best plan it can. :)

Tray2 left a reply on Database Design For A Tv Series App

  1. A show can have many seasons
  2. A season can have many episodes
  3. An episode can only belong to one season
  4. A season of one show can only belong to one show

I would probably not have a seasons table since it would only be filled with the show number and the season number. I would put the season in the episodes table to start with but that is up to you.

Tray2 left a reply on Do You Use Vim?

Vim is an awesome editor that takes some time to master fully but once you do ....

There is a really good course here on how to configure it.

https://laracasts.com/series/vim-mastery

24 Mar
1 month ago

Tray2 left a reply on Need Workaround To Run Composer.

Have you removed the phar extension on the composer file?

If not you should be able to use the same trick and the run php <path to composer>/composer.phar. I haven't tried but it should be a plausible workaround.

Tray2 left a reply on Only Update Db Field If Input Is Set

There is a validation that you could use required_if https://laravel.com/docs/5.8/validation#rule-required-if

Otherwise you can always check if which value is set and then validate it.

if (isset($request->get('this_id')) &&  !isset($request->get('that_id'))) {
    //validate this_id
} else {
    //validate that_id
}

However it's not neccesarry to split them up since you should pass them both all the time and it will update if needed.

Tray2 left a reply on How To Add Url To Query Results

You do that in your view.

<a href="/movies/{{ $movie->id }}">{{ $movie->title }}</a>

And so on.

Tray2 left a reply on Laravel Ancessor

I assume this is $ we are talking then storeit as cents and as Nash pointed out use number_format.

23 Mar
1 month ago

Tray2 left a reply on How To Increase Storage Space On Homestead Vagrant?

I would also go with adding a new drive then mount it to the proper directory.

Tray2 left a reply on How Many Rows Are Too Many Rows For Browsers?

Yes they can but that is not the issue. The issue is load times.

First your server must the fast enough to get the data and parse the view for you.

Let's sat each row is 500 bytes with a template of 20Kb. That would make the page about 605Kb. This needs to be send over the network and some users are still on really slow connections.

Then depending on your structure of the page and the styles used and any javascript you have on your page will make the rendering time increase.

So I suggest you try at some site that helps you with this.

Here are some examples

https://serps.com/library/how-to-measure-your-website-speed-and-load-times/