Tray2

Tray2

Member Since 4 Years Ago

Solna

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

Experience Points 142,370
Experience Level 29

2,630 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 1111
Lessons
Completed
Best Reply Awards 63
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 May
21 hours ago

Tray2 left a reply on How To Multiple Column Validation In Laravel

I've done this to validate on two fields

[
            'first_name' => 'required|unique:authors,first_name,' . null . ',id,last_name,'. $request->last_name,
            'last_name' => 'required'
 ]
22 May
1 day ago

Tray2 left a reply on Single Code Base - Multiple Projects

I would probably use forks for each project and just version control the files specific to each project.

Tray2 left a reply on States, Cities, Zip Codes And Counties Database Tables (best Table Design For Populating Dropdowns)

Seeding can be used both for testing and for seeding the production data.

Tray2 left a reply on Edit Blade View

Try

php artisan cache:clear

Tray2 left a reply on Edit Blade View

Run this command and try again

php artisan view:clear

Tray2 left a reply on States, Cities, Zip Codes And Counties Database Tables (best Table Design For Populating Dropdowns)

I would not create a table for each state's cities but rather use a foreign key to connect them.

Something like

mysql> desc states;
+----------------+------------------+------+-----+---------+----------------+
| Field          | Type             | Null | Key | Default | Extra          |
+----------------+------------------+------+-----+---------+----------------+
| id             | int(10) unsigned | NO   | PRI | NULL    | auto_increment |
| name           | varchar(255)     | NO   |     | NULL    |                |
| short_name          | varchar(10)     | NO   | UNI | NULL    |                |
| created_at     | timestamp        | YES  |     | NULL    |                |
| updated_at     | timestamp        | YES  |     | NULL    |                |
+----------------+------------------+------+-----+---------+----------------+ 

mysql> desc cities;
+----------------+------------------+------+-----+---------+----------------+
| Field          | Type             | Null | Key | Default | Extra          |
+----------------+------------------+------+-----+---------+----------------+
| id             | int(10) unsigned | NO   | PRI | NULL    | auto_increment |
| name           | varchar(255)     | NO   |     | NULL    |                |
| state_id          | int(10)unsigned     | NO   | UNI | NULL    |                |
| password       | varchar(255)     | NO   |     | NULL    |                |
| created_at     | timestamp        | YES  |     | NULL    |                |
| updated_at     | timestamp        | YES  |     | NULL    |                |
+----------------+------------------+------+-----+---------+----------------+

Or you could use the state's acronym together with the name to create the primary key.

Tray2 left a reply on Migration Problem: Cannot Add Foreign Key Constraint In Laravel

Do a descon both tables and compare them.

mysql> desc users;
+----------------+------------------+------+-----+---------+----------------+
| Field          | Type             | Null | Key | Default | Extra          |
+----------------+------------------+------+-----+---------+----------------+
| id             | int(10) unsigned | NO   | PRI | NULL    | auto_increment |
| name           | varchar(255)     | NO   |     | NULL    |                |
| email          | varchar(255)     | NO   | UNI | NULL    |                |
| password       | varchar(255)     | NO   |     | NULL    |                |
| remember_token | varchar(100)     | YES  |     | NULL    |                |
| created_at     | timestamp        | YES  |     | NULL    |                |
| updated_at     | timestamp        | YES  |     | NULL    |                |
+----------------+------------------+------+-----+---------+----------------+

This is my users table.

Tray2 left a reply on Edit Blade View

Yes you do since you call it $shares in your controller instead of $share.

Eaither change in the controller or the view. I'd go for the controller option.

Tray2 left a reply on Migration Problem: Cannot Add Foreign Key Constraint In Laravel

The id of the users table must be the same type as the one in your foreign key.

Tray2 left a reply on Edit Blade View

Try removing the @foreach since it's only one share found you don't need to loop over it.

21 May
2 days ago

Tray2 left a reply on How Do I Get The Updated_at

So if created_at equals updated_at then it's a new project and if updated_at greater then created_atit's published?

I suggest you add a published_at field to your table and use it to determine if it's published or not.

How long is a project new? five days?

You can use carbon for that comparsion

https://carbon.nesbot.com/docs/

Tray2 left a reply on UI To Build Dynamic Forms

The package @Ty suggested is not recommended since it clutters up your views and makes them harder to debug.

It's very easy but quite tedious to create lots of forms but it's still the best way to do it.

Tray2 left a reply on Simple Use Of Eloquent Join

Call me old school but I prefer the old way of doing joins and keeping my Eloquent simple so I'd hide the implementation in a database view so I can do this instead.

$records = RecordsView::where('field', $value);
20 May
3 days ago

Tray2 left a reply on Dynamic Table

Something like

<tr>
@foreach($collection->keys() as $key)

    <th>{{ $key }} </th>

@endforeach
</tr>
<tr>
@foreach($collection as $record)
   @foreach($collection->keys() as $key)
    <th>{{ $collection[$key]</th>
    @endforeach
@endforeach
</tr>

might work

Tray2 left a reply on Laravel Migration: Drop View With DB::statement Doesn't Work

Then it's better to use

CREATE OR REPLACE VIEW

Then it will always recreate it.

19 May
4 days ago

Tray2 left a reply on FormRequest 'nice Names' For Arrays

You can alway use custom messages. Something like

protected $messages = ['field.required' => 'This bad boy must be unique'];

public function store(Request $request)
{
   $request->validate(['field' => 'required], $this->messages);
   
   //Do the storing here
}

Tray2 left a reply on Artisan Db:seed Gives "Unable To Locate Factory With Name [default] ..."

Check that you have the correct classes in your use statments since this is most likely the issue..

Tray2 left a reply on Fake Data Generator Using Facker

That usally means that it can't find your factory class.

Check your use statements and make sure that they are correct.

Tray2 left a reply on Laravel Validation Rules

I have a bad feeling in my stomach when reading your code. When you start using numbers in your field names you have a bad design. I suggest using another table for all those fields that way it's scalable out of the box.

Classic one to many scenario.

Tray2 left a reply on Laravel Form Builder

Yes, don't use the form builder. It's not needed and it creates code that is harder to read and debug.

Tray2 left a reply on Laravel Migration: Drop View With DB::statement Doesn't Work

Try removing IF EXISTS. It might solve your issue. If the syntax is wrong it should squawk.

Tray2 left a reply on Cannot Add Foreign Key On Laravel Tables

What database are you using?

18 May
5 days ago

Tray2 left a reply on Transaction Inside Transaction (nested Transactions) - Any Problems?

No, it will not work properly since you can't commit each session by itself in MySQL. In the Oracle database you can you autonomous transactions where each statement can be commited without commiting everything in the session.

While it would work to write it that way you wouldn't benifit from it.

Tray2 left a reply on Laravel - Access Denied For User

MariaDB is a fork of MySQL created by some of the MySQL developers who didn't like the way MySQL was going.

Tray2 left a reply on Slug

Tray2 left a reply on Laravel - Access Denied For User

It has to do with the hashing algorithm in MySQL 8. You can configure it to use the legacy hashing. That way you can use version 8. However I suggest you uninstall MySQL and install MariaDB instead.

https://community.jaspersoft.com/wiki/uninstall-mysql-mac-os-x

https://www.javatpoint.com/how-to-install-mariadb-on-mac

Tray2 left a reply on Laravel - Access Denied For User

There are some issues with MySQL 8 and PHP. They have changed stuff in the connection in MySQL 8. There might have been a fix in later versions of PHP so try upgrading it. Or use MariaDB or an earlier 5.7 version of MySQL.

Tray2 left a reply on Simple Use Of Eloquent Join

Hm,

Looks a bit like it's more code to add then just

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

But then again I just took a fast peek at the docs.

Tray2 left a reply on How To Optimize My Controller ?

You can refactor out the validate to the Model class and just pass the rules.

protected function validate(Request $request, $rules)
{
    return $request->validate($rules);
} 

And in your controller

protected $rules = ['email' => 'required|email'];

public function update(Request $request)
{
     $this->validate($request, $this->rules);

     $user = User::find(Auth::user()->id);
     $user->email = $request->email;
     $user->update();

     return response()->json([]);
} 

Or similar.

Tray2 left a reply on Eloquent Generates Valid SQL That Throws An Error.

Aah I didn't read that it was postgres and I'm not familiar with that dialect of SQL.

Tray2 left a reply on Eloquent Generates Valid SQL That Throws An Error.

The issue is

now() + INTERVAL '1 MONTH'

The query should look more like this.

SELECT * 
FROM mydb 
WHERE creationdate BETWEEN "2011-01-01" 
                   AND DATE_ADD("2011-01-01", INTERVAL 6 MONTH) - INTERVAL 1 DAY
GROUP BY MONTH(creationdate);
17 May
6 days ago

Tray2 left a reply on Laravel 5.8 Does Not Use Sqlite For Testing

Change the server tag to env and it should work again.

Tray2 left a reply on How To Delete Multiple Rows In Storage?

The code looks like it should work.

I suggest doing a dd on $country and see if both paths are defined and then check that the files are named correctly. It could be as easy as the filename is in the wrong case.

Tray2 left a reply on Laravel 5.8 Does Not Use Sqlite For Testing

Make your phpunit.xml look like this

<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
         backupStaticAttributes="false"
         bootstrap="vendor/autoload.php"
         colors="true"
         convertErrorsToExceptions="true"
         convertNoticesToExceptions="true"
         convertWarningsToExceptions="true"
         processIsolation="false"
         stopOnFailure="false"
         printerClass="Codedungeon\PHPUnitPrettyResultPrinter\Printer">
    <testsuites>
        <testsuite name="Feature">
            <directory suffix="Test.php">./tests/Feature</directory>
        </testsuite>

        <testsuite name="Unit">
            <directory suffix="Test.php">./tests/Unit</directory>
        </testsuite>
    </testsuites>
    <filter>
        <whitelist processUncoveredFilesFromWhitelist="true">
            <directory suffix=".php">./app</directory>
        </whitelist>
    </filter>
    <php>
        <env name="APP_ENV" value="testing"/>
        <env name="TELESCOPE_ENABLED" value="false" />
        <env name="BCRYPT_ROUNDS" value="4"/>
        <env name="CACHE_DRIVER" value="array"/>
        <env name="SESSION_DRIVER" value="array"/>
        <env name="QUEUE_DRIVER" value="sync"/>
        <env name="MAIL_DRIVER" value="array"/>
        <env name="DB_CONNECTION" value="sqlite"/>
        <env name="DB_DATABASE" value=":memory:"/>

    </php>
</phpunit>
16 May
1 week ago

Tray2 left a reply on Update Data With Current Image File Using Same Form Request From Store Function

You can do that by only having the rules that are common between your store and update methods. Then in the store method you send additional rules into it.

Below is how I did it for a project.

protected function validateBook(Request $request, $validationRules = [])
    {
        $rules = array_merge([
            'title' => 'required',
            'series' => 'required',
            'part' => [
                'required_unless:series,Standalone',
                'numeric',
                'nullable'
            ],
            'format_id' => 'required|exists:formats,id',
            'genre_id' => 'required|exists:genres,id',
            'isbn' => [
                'required',
                'regex:/^(97(8|9))?\d{9}(\d|X)$/'
            ],
            'released' => ['required', 'integer', 'between:1800,' . Carbon::now()->addYear(1)->year],
            'reprinted' => ['nullable', 'integer', 'between:1800,' . Carbon::now()->addYear(1)->year],
            'pages' => 'required|integer',
            'blurb' => 'required'
        ], $validationRules);

        return $request->validate($rules);
    }

Tray2 left a reply on Create Notification System Using Cron

Not really an issue you compare today's date with the the end date of the subscription. You can use Carbon for that https://carbon.nesbot.com/docs/#api-comparison

And if end date is greater than today's date it's a valid subscription.

Tray2 left a reply on Can't Connect To Mysql (Mac)

There seems to be a permission issue Permission denied

Try appending sudo to your command.

sudo brew services restart mysql

Tray2 left a reply on Create Notification System Using Cron

I'd probaly have a table called subscription_user and in it you have a column called valid_to and then check against it if the difference between them with carbon and if the diff is positive it's a valid subscription and if it's not it's invalid.

There is a new series regarding queues and workers which you should check to see how to use them.

https://laracasts.com/series/queue-it-up

Tray2 left a reply on 404 Page Instead Of {METHOD} Not Supported For This Route

Check the fallback route

https://laravel.com/docs/5.8/routing#fallback-routes

Route::fallback(function () {
    //Send to 404 or whatever here.
});

Tray2 left a reply on Switching Team Subscription

I went from monthly to yearly last summer and it worked like this

  1. The ongoing subscription was canceled
  2. The amount for the remaining period was deducted from the new subscription cost.

It probably works the same way with team subscriptions.

Tray2 left a reply on Create Notification System Using Cron

I would not use a cron for that.

I would add something like this in the master layout

@auth

    @if(Auth()->user->showSubcriptionNotice())
        Hey man, only  {{ Auth()->user->subscription->daysLeft() }} days left on your subscription.
    @endif
@endauth

As for the mail you should use a queue worker that checks all your users to see which has 5 or less days left.

Tray2 left a reply on What's Wrong With This?

Try changing

return view('/home')->with(compact('profilelist'));

to

`` return view('/home', compact('profilelist'));

Tray2 left a reply on Wizard Forms With Package Form Builder !

Probably but since you want to do it with Vue and possibly Vue components I advise against it and recommend using regular html in your components.

Tray2 left a reply on SQLite - Unique Constraint Failed

@devfrey Good eyes but wrong suggestion.

The id should never ever be added with code, the database should always increment it that way it will never be a duplicate.

Tray2 left a reply on SQLite - Unique Constraint Failed

This error is thrown since you are not removing the created user after each test. So when the test tries to create the user it already exists thus the error.

I suggest you use an in memory database for your testing. The other way is to have a teardown in your test class.