Tray2

Tray2

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

Member Since 5 Years Ago

Solna

Experience Points
235,500
Total
Experience

4,500 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
1253
Lessons
Completed
Best Reply Awards
175
Best Reply
Awards
  • start-engines Created with Sketch.

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • first-thousand Created with Sketch.

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • 1-year Created with Sketch.

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • 2-years Created with Sketch.

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • 3-years Created with Sketch.

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • 4-years Created with Sketch.

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • 5-years Created with Sketch.

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • school-session Created with Sketch.

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • welcome-newcomer Created with Sketch.

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • full-time-student Created with Sketch.

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • pay-it-forward Created with Sketch.

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • subscriber-token Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer-token Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • lara-evanghelist Created with Sketch.

    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 Created with Sketch.

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • lara-veteran Created with Sketch.

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • 10k-strong Created with Sketch.

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • lara-master Created with Sketch.

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • laracasts-tutor Created with Sketch.

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • laracasts-sensei Created with Sketch.

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • top-50 Created with Sketch.

    Top 50

    Earned once your experience points ranks in the top 50 of all Laracasts users.

Level 48
235,500 XP
Jan
19
21 hours ago
Activity icon

Replied to Resize Image Before Save

Like @nakov said use Intervention for that.

http://image.intervention.io/

Activity icon

Replied to Having Trouble Setting Up A Regex For Checking Url

You are most welcome :)

Activity icon

Awarded Best Reply on Having Trouble Setting Up A Regex For Checking Url

You can use the test method to do the comparsion. I also missed that you need to escape the /

var patt = /events\/.*/;
patt.test(this.$router.currentRoute.path) ? console.log('true') : console.log('false');

https://www.w3schools.com/js/js_regexp.asp

Activity icon

Replied to Having Trouble Setting Up A Regex For Checking Url

You can use the test method to do the comparsion. I also missed that you need to escape the /

var patt = /events\/.*/;
patt.test(this.$router.currentRoute.path) ? console.log('true') : console.log('false');

https://www.w3schools.com/js/js_regexp.asp

Activity icon

Replied to Thoughts About Validation Testing

I've started with this and I think I like it alot.

This is what I have so far on the validation tests for a record

    /**
    * @test
    * @dataProvider recordValidationProvider
    */
    public function record_form_validation($formInput, $formInputValue)
    {
        $record = factory(Record::class)->make([
            $formInput => $formInputValue
        ]);
        $this->signIn();
        $response = $this->post('/records', $record->toArray());

        $response->assertStatus(302);
        $response->assertSessionHasErrorsIn($formInput);
    }

    public function recordValidationProvider()
    {
        return [
            'title is required' => ['title', ''],
            'released is required' => ['released', ''],
            'release cant be earlier than 1800' => ['released', 1799],
            'release cant be more than one year in the future' => ['released', Carbon::now()->addYear(2)->year],
        ];
    }

@bugsysha thanx again m8 :)

Activity icon

Replied to Having Trouble Setting Up A Regex For Checking Url

In regexp the * is a quantifier and the . is a wildcard so try adding a dot infront of the *

this.$router.currentRoute.path == `/events/.*/` ? console.log('true') : console.log('false');
Jan
18
1 day ago
Activity icon

Replied to Thoughts About Validation Testing

I will try that out tomorrow. Thnx m8.

A table with more fields like this will be intresting to try that out on.

Schema::create('books', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->string('title');
            $table->string('series');
            $table->unsignedInteger('part')->nullable();
            $table->unsignedBigInteger('format_id');
            $table->unsignedBigInteger('genre_id');
            $table->string('isbn');
            $table->unsignedInteger('released');
            $table->unsignedInteger('reprinted')->nullable();
            $table->unsignedInteger('pages');
            $table->text('blurb');
            $table->timestamps();
Activity icon

Replied to Thoughts About Validation Testing

Dataproviders is a good idea I might look into that a bit more and see if that is usable in this case. On a small table with few fields I think dataproviders will function nicely but for a big table with lots of fields they migth get cluttered with big and messy arrays. I will try that out tomorrow and see how it looks and feels.

Activity icon

Started a new Conversation Thoughts About Validation Testing

I was thinking a bit about validation testing today and normaly I do something like this.

I start with the happy path test.

    /**
    * @test
    */
    public function a_valid_author_can_be_stored()
    {
        $author = factory(Author::class)->make([
            'first_name' => 'Robert',
            'last_name' => 'Jordan',
        ]);

        $this->post('/authors', $author->toArray());
        $this->assertEquals(1, Author::count());
    }

Then I move on and create the first validation test

 /**
    * @test
    */
    public function author_first_name_is_required()
    {
        $author = factory(Author::class)->make([
            'first_name' => null,
            'last_name' => 'Jordan',
        ]);

        $this->post('/authors', $author->toArray())->assertSessionHasErrors('first_name');
        $this->assertEquals(0, Author::count());
    }

And I create one for each field and for each validation rule.

This is all well and good. However I do the same thing again for the update method.

The happy path test

 /**
    * @test
    */
    public function a_valid_author_can_be_updated()
    {
        $author = factory(Author::class)->create([
            'first_name' => 'Steven',
            'last_name' => 'Jordan'
        ]);

        $author->first_name = 'Robert';

        $this->put('/authors/' . $author->id, $author->toArray());
        $this->assertEquals('Jordan, Robert', $author->fresh()->name);
    }

and the first validation test

/**
    * @test
    */
    public function authors_first_name_is_required_to_update_an_author()
    {
        $author = factory(Author::class)->create([
            'first_name' => 'Steven',
            'last_name' => 'Jordan'
          ]);

        $author->first_name = null;

        $this->put('/authors/' . $author->id, $author->toArray())->assertSessionHasErrors(('first_name'));

        $this->assertEquals('Steven', $author->fresh()->first_name);
    }

This is all well and good but it feels a bit repetitive and actually quite boring to write. So my thought was this.

I keep the happy path tests as is and then combine the store and update validations. Something like

 /**
    * @test
    */
    public function author_first_name_is_required()
    {
    $author = factory(Author::Class)->create();
        $missingFirstName = factory(Author::class)->make([
            'first_name' => null,
            'last_name' => 'Jordan',
        ]);

        $this->post('/authors', $author->toArray())->assertSessionHasErrors('first_name');
        $this->assertDatabaseMissing('authors', ['first_name' => null]);

    $author = factory(Author::class)->make([
            'first_name' => null,
            'last_name' => 'Jordan',
        ]);
    $this->put('/authors/' . $author->id, $missingFirstNamer->toArray())->assertSessionHasErrors(('first_name'));

        $this->assertEquals('Steven', $author->fresh()->first_name);
    }

It can probably be made even cleaner and more readable but before I start doing that what is your intake on this?

I know that you should only test one thing and keep the assertions per test to a minimum but since it's the same validation rules for both store and update the could go together.

Activity icon

Replied to CSRF Cookie In Iframe On Other Domain (chrome Blocking Third Party Cookies)

Ooh that is not a good practice at all.

I suggest you use the other domain as an api that supplies the partial instead.

This video explains it very well

https://laracasts.com/series/javascript-techniques-for-server-side-developers

Then you don't need to use an iframe at all.

Activity icon

Replied to API Is Giving Response For POSTMAN But From Browser I Am Getting 403

Show us what you are trying to do in code and show us the error message.

Activity icon

Awarded Best Reply on HTML Tags Become Disabled

Tailwind resets all the browser defaults. Then you need to apply classes to each element you want to style.

Activity icon

Awarded Best Reply on Optimize Codes

You are the god of messy code.

Take this part for example

   if ($sortBy != null) {
        if ($sortBy == SortingOptionEnum::LOWESTPRICE) {
            $pct = 'product_category_translations as t';
                $products = $products
                    ->join('product_price_lists as ppl', 'ppl.product_catalog_id', '=', 'product_catalogs.id')
                    ->join('product_catalog_product_category as c', 'c.product_catalog_id', 'product_catalogs.id')
                    ->join($pct, 't.product_category_id', '=', 'c.product_category_id')
                    ->where('t.name', $range)
                    ->groupBy('product_catalogs.id')
                    ->orderBy('ppl.price')
                    ->select('product_catalogs.*');
        }

        if ($sortBy == SortingOptionEnum::HIGHESTPRICE) {
            $pct = 'product_category_translations as t';
                $products = $products
                    ->join('product_price_lists as ppl', 'ppl.product_catalog_id', '=', 'product_catalogs.id')
                    ->join('product_catalog_product_category as c', 'c.product_catalog_id', 'product_catalogs.id')
                    ->join($pct, 't.product_category_id', '=', 'c.product_category_id')
                    ->where('t.name', $range)
                    ->groupBy('product_catalogs.id')
                    ->orderByDesc('ppl.price')->select('product_catalogs.*');
        }
    }

That could easily be cleaned up. Something like


if ($sortBy != null) {
    $sortDiretction = ($sortBy === SortingOptionEnum::LOWESTPRICE) ?  'asc' : 'desc'; 
    $pct = 'product_category_translations as t';
    $products = $products
        ->join('product_price_lists as ppl', 'ppl.product_catalog_id', '=', 'product_catalogs.id')
        ->join('product_catalog_product_category as c', 'c.product_catalog_id', 'product_catalogs.id')
        ->join($pct, 't.product_category_id', '=', 'c.product_category_id')
        ->where('t.name', $range)
        ->groupBy('product_catalogs.id')
        ->orderBy('ppl.price', $sortinDirection)
        ->select('product_catalogs.*');
}

It can of course be cleaned up even more.

Activity icon

Replied to URL Change \ To /

@fylzero True but not likely.

My guess is that DIRECTORY_SEPARATOR is used and on Windows systems it becomes \ so I always use hardcoded /

https://dev.to/c33s/always-use--as-directory-seperator-in-php-43l7

Activity icon

Replied to URL Change \ To /

You most likely add that backslash somewhere in your code so I suggest looking for that instead of replacing it first.

Activity icon

Replied to File:: Properties ?

Like I said in the previous thread you can use Intervention for this which is the easiest way.

Or you can use the gd library and use getimagesize.

https://www.php.net/manual/en/function.getimagesize.php

I'd go with Intervention since it has a nice laravel wrapper.

$width = Image::make('public/foo.jpg')->width();
Activity icon

Replied to Optimize Codes

@fylzero yepp.

Was in a bit of a hurry and wrote the ternary wrong. I've updated the code in my previous comment.

Activity icon

Awarded Best Reply on SplFileInfo::getSize(): Stat Failed For C:\xampp\tmp\php1F17.tmp

You should probaly use the $path in this statement instead of $request->file('image')

$imgsizes = $request->file('image')->getSize();
Activity icon

Replied to SplFileInfo::getSize(): Stat Failed For C:\xampp\tmp\php1F17.tmp

If you divide 90788 with 1024 you get 88.66.

So you get the filesize in bytes.

Activity icon

Replied to SplFileInfo::getSize(): Stat Failed For C:\xampp\tmp\php1F17.tmp

I'd use number for that.

You can use varchar if you want.

Blob is for binary large object

Activity icon

Replied to HTML Tags Become Disabled

A style reset is used to make it easier for consistensy between browsers.

All tags might have different default style depending on the browser so to make it easier and more consistent you usually reset the style so that all elements are unstyled. Then you have full control over how your page looks and feels.

Activity icon

Replied to Laravel Strange 419 Behavior

Different server setups is my guess.

Activity icon

Replied to Deploying Laravel App In Nginx Server Throws Error.....

I would take a look at the file and directory permissions/owner. If the diretory is not writable then you can't do file_put_contents.

Activity icon

Replied to HTML Tags Become Disabled

Tailwind resets all the browser defaults. Then you need to apply classes to each element you want to style.

Activity icon

Replied to How Can I Set The Default Value?

I did this

<select name="genre_id" required>
            @if(old('genre_id'))
            <option value="" disabled>Select your genre</option>
            @else
            <option value="" disabled {{ isset($book) ? '' : 'selected' }}>Select your genre</option>
            @endif
            @foreach($genres as $genre)
            <option value="{{ $genre->id }}" {{ isset($book) && $book->genre_id == $genre->id ? 'selected' : '' }}>{{ $genre->genre }}</option>
            @endforeach
</select>
Activity icon

Replied to SplFileInfo::getSize(): Stat Failed For C:\xampp\tmp\php1F17.tmp

You should probaly use the $path in this statement instead of $request->file('image')

$imgsizes = $request->file('image')->getSize();
Activity icon

Replied to Laravel Strange 419 Behavior

Not having seen any code from your application and not understanding what you mean with "opens several hours later".

Is the user closing the browser and then reopens it? Is the user just leaving the tab open in the background and comes back to it?

You can set session timeouts on the server and it might be that it invalidates the session after just a couple of minutes or so.

Activity icon

Replied to Laravel Strange 419 Behavior

That is normal behaviour. The user has probably lost his session and the csrf has become invalid.

Activity icon

Awarded Best Reply on Factory - Use Attributes Of Recently Created Record

Save the product in a variable then. Something like

$factory->define(OrderProduct::class, function (Faker $faker) {
    $product =  factory(Product::class)->create();   
return [
        'order_id' => factory(Order::class),
        'product_id' => $product->id,
        'original_price' => $product->price,
        'quantity' => $faker->randomDigitNotNull,
    ];
});
Activity icon

Replied to Factory - Use Attributes Of Recently Created Record

Save the product in a variable then. Something like

$factory->define(OrderProduct::class, function (Faker $faker) {
    $product =  factory(Product::class)->create();   
return [
        'order_id' => factory(Order::class),
        'product_id' => $product->id,
        'original_price' => $product->price,
        'quantity' => $faker->randomDigitNotNull,
    ];
});
Activity icon

Replied to Laravel New Generates Errors

Can you run composer create-project laravel/laravel laraapp?

Activity icon

Replied to Optimize Codes

You are the god of messy code.

Take this part for example

   if ($sortBy != null) {
        if ($sortBy == SortingOptionEnum::LOWESTPRICE) {
            $pct = 'product_category_translations as t';
                $products = $products
                    ->join('product_price_lists as ppl', 'ppl.product_catalog_id', '=', 'product_catalogs.id')
                    ->join('product_catalog_product_category as c', 'c.product_catalog_id', 'product_catalogs.id')
                    ->join($pct, 't.product_category_id', '=', 'c.product_category_id')
                    ->where('t.name', $range)
                    ->groupBy('product_catalogs.id')
                    ->orderBy('ppl.price')
                    ->select('product_catalogs.*');
        }

        if ($sortBy == SortingOptionEnum::HIGHESTPRICE) {
            $pct = 'product_category_translations as t';
                $products = $products
                    ->join('product_price_lists as ppl', 'ppl.product_catalog_id', '=', 'product_catalogs.id')
                    ->join('product_catalog_product_category as c', 'c.product_catalog_id', 'product_catalogs.id')
                    ->join($pct, 't.product_category_id', '=', 'c.product_category_id')
                    ->where('t.name', $range)
                    ->groupBy('product_catalogs.id')
                    ->orderByDesc('ppl.price')->select('product_catalogs.*');
        }
    }

That could easily be cleaned up. Something like


if ($sortBy != null) {
    $sortDiretction = ($sortBy === SortingOptionEnum::LOWESTPRICE) ?  'asc' : 'desc'; 
    $pct = 'product_category_translations as t';
    $products = $products
        ->join('product_price_lists as ppl', 'ppl.product_catalog_id', '=', 'product_catalogs.id')
        ->join('product_catalog_product_category as c', 'c.product_catalog_id', 'product_catalogs.id')
        ->join($pct, 't.product_category_id', '=', 'c.product_category_id')
        ->where('t.name', $range)
        ->groupBy('product_catalogs.id')
        ->orderBy('ppl.price', $sortinDirection)
        ->select('product_catalogs.*');
}

It can of course be cleaned up even more.

Jan
17
2 days ago
Activity icon

Replied to Filter By File Extention On Remote Disk (ftp) And Copy Them To Local Dir

I'd probably do something like this

function getDirContents(){
    return scandir('./');
}

function getFiles($contentList)
{
    $files = [];
    $allowedTypes = ['xml'];

    foreach($contentList as $row) {
        if(is_file($row)) {
            $extension = pathinfo($row, PATHINFO_EXTENSION);
            if(in_array($extension, $allowedTypes)) {
                $files[] = $row;
            }
        }
    }

    return $files;
}

function moveFiles($files )
{
    //move code here
}

function main()
{
    $files = getDirContents();
    $xmlFiles = getFiles($files);
    moveFiles($xmlFiles);
}

main();
Jan
16
3 days ago
Activity icon

Replied to Hashing And Storing Large Data In MySQL Database,

There is no way to securely encrypt something and still save space, To achieve that you need to first encrypt then compress it.

Jan
14
5 days ago
Activity icon

Replied to Artisan Commands With SSH

That is not so strange.

There are two (or more) php installed. Your webserver uses 7.4 while your client points to 4.4.

If you do which php it will give you the path to the one you are using (4.4). So you need to make your 7.4 installation default. Not knowing your system setup but something like

sudo update-alternatives --set php /usr/bin/php7.4

Should do the trick.

Jan
13
6 days ago
Activity icon

Replied to Single Javascript Bundle Or Separate Bundles

I would put all the common JS into one bundle/file and keep the page specific stuff in their own files. Something like

  • common.js (All common JS aka JS that is used in more than one page)
  • page1.js (Page1 specific js)
  • page2.js (Page2 specific js)
  • page3.js (Page3 specific js)

Of course it also depends a bit on the size of the files. If we are talking just a few Kb for the page specific stuff then I'd put it in the same file/bundle.

Activity icon

Replied to Optimizing Query

I suggest you change ->get() to ->toSql() and dump the query. Then you log into your favorite sql gui or the mysql prompt and run explain <your query> that should tell you what is taking time. It can be a bit tricky to understand but look for Full table scan and Cartesian products

The output will look something like this

MariaDB [mediabase]> explain select * from book_views;
+------+--------------------+-------+-------+---------------+---------+---------+------+------+--------------------------------------------------------+
| id   | select_type        | table | type  | possible_keys | key     | key_len | ref  | rows | Extra                                                  |
+------+--------------------+-------+-------+---------------+---------+---------+------+------+--------------------------------------------------------+
|    1 | PRIMARY            | b     | ALL   | NULL          | NULL    | NULL    | NULL | 2    |                                                        |
|    1 | PRIMARY            | g     | ALL   | PRIMARY       | NULL    | NULL    | NULL | 2    | Using where; Using join buffer (flat, BNL join)        |
|    1 | PRIMARY            | f     | ALL   | PRIMARY       | NULL    | NULL    | NULL | 2    | Using where; Using join buffer (incremental, BNL join) |
|    6 | DEPENDENT SUBQUERY | bi    | ALL   | NULL          | NULL    | NULL    | NULL | 2    | Using where                                            |
|    5 | DEPENDENT SUBQUERY | s     | ALL   | NULL          | NULL    | NULL    | NULL | 1    | Using where                                            |
|    4 | DEPENDENT SUBQUERY | a     | ALL   | PRIMARY       | NULL    | NULL    | NULL | 2    |                                                        |
|    4 | DEPENDENT SUBQUERY | ab    | ALL   | NULL          | NULL    | NULL    | NULL | 4    | Using where; Using join buffer (flat, BNL join)        |
|    3 | DEPENDENT SUBQUERY | a     | index | PRIMARY       | PRIMARY | 8       | NULL | 2    | Using index                                            |
|    3 | DEPENDENT SUBQUERY | ab    | ALL   | NULL          | NULL    | NULL    | NULL | 4    | Using where; Using join buffer (flat, BNL join)        |
+------+--------------------+-------+-------+---------------+---------+---------+------+------+--------------------------------------------------------+
9 rows in set (0.001 sec)
Activity icon

Replied to Non-Schema Data Migrations (Data Fixes)

If I need to change data like that I use plain SQL. It's fast it's straight forward without any fuss.

In my opinion all data manipulation should be done using SQL since it's most likely a one time deal. If it is something you need to run on a regular basis then you could do a artisan command but that suggest there might be something wrong with your database model.

Activity icon

Awarded Best Reply on MySQL SELECT COUNT With Multiple Conditions

Is there an error message or does it just give you 0?

If you need to run it standalone you need to add the second table to your FROM clause

SELECT COUNT(Log_ns.n_s) 
FROM Log_ns,
        Magasins    
WHERE Log_ns.id_produit = Magasins.produit_id 
AND DATE(Log_ns.created_at) = DATE(Magasins.created_at)) as qte_ins

My guess is that you don't have posts that are the same.

Jan
12
1 week ago
Activity icon

Replied to Laravel Forge DB Mysql Connection Via Desktop Client Issue

That has nothing to do with forge.

You need to set up a ssh tunnel in TablePlus.

https://tableplus.com/blog/2019/08/ssh-tunnel-secure-database-connection.html

Activity icon

Replied to Different Models, Same Table

To put it like this.

A Question is a question regardless of how many possible answers there are.

So I would do a Question model and an Answer model.

The Answer model determines how many answers there are.

Activity icon

Replied to How To Return Laravel Migration Table?

DB::getSchemaBuilder()->getColumnListing('users');

Would give you the structure of the users table.

Activity icon

Replied to Laravel Valet Host Issue

What version of php have you installed?

Try running laravel use [email protected] exchange the xto your version of php.

Activity icon

Replied to Seed

Like @jlrdw said it's optional. As an example if you build a library application you might have some default values that you want to store in the database such as formats, genres and countries. So instead of inserting them manually you can create a seeder for those tables. You can of course use plain SQL for this if you like.

Jan
11
1 week ago
Activity icon

Replied to Does Laravel V6 Support MySQL V8 New Authentication Method?

The thing that I don't like is that the introduced Oracle SQL syntax for some of the new functionality in MySQL 8 and that makes the otherwise pretty clean syntax of MySQL a bit harder to read.

Activity icon

Replied to File Permissions Not Working

The easiest way to do this is to use a shared folder instead of a samba connection.

https://robertfilter.net/blog/computers/virtualbox-how-to-share-a-folder-from-windows-to-a-linux-virtual-machine.html

If you want to continue using samba you need to add the samba user to www-data and set the default user group in your samba config

https://unix.stackexchange.com/questions/164884/how-to-set-default-group-for-files-created-in-samba-share

Activity icon

Replied to DataBase Structure

Not really understanding your database model but here is how I would do it.

I would have a check_in and a check_out field in my reservations table. Then I would not store the number of available rooms in any table since it could become falsey. I would use a calculated value for that instead of a static one that I need to update every time I do something with the rooms.

So to get the free rooms I'd use a database view that I can easely query every time I need to check the avaiability of rooms.