Tray2

Tray2

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

Member Since 5 Years Ago

Solna

Experience Points
303,360
Total
Experience

0 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
1353
Lessons
Completed
Best Reply Awards
256
Best Reply
Awards
  • start your 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-in-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 Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • evangelist 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 50
303,360 XP
Jul
09
5 hours ago
Activity icon

Replied to Jquery To Regular Ajax

I use the fetch api instead of the old way with xmlhttprequest.

async function getRequest(url, parameters = {}) {
  try {
      showLoading();
      let responsePromise = await fetch(connectionString + url, { method: 'GET', headers: parameters});
      if(! responsePromise.ok) {
          hideLoading();
          throw new Error(responsePromise.status );
      }
      hideLoading();
      return await responsePromise.json();
  } catch (error) {
      return error;
  }
} 

I call the function like this

async function isUrgent() {
  const params = {
      'partno': partInfo.partno,
      'trailer_id': activeMasterLabel.trailer_id,
      'truck_id': activeMasterLabel.truck_id
  };

  const response = await getRequest('/endpoint', params);

  if (response.message != null) {
    showAlert(`Could not check if part is urgent (${ response.message })`);
  } else {
    return (response.urgent != 0);
  }
}

The connection string is a global variable in this case but that can easily be a parameter sent in or even hardcoded

Jul
08
1 day ago
Activity icon

Replied to DB Design Best Practice

I would go with a single users table and then have user roles.

There are several ways of doing that.

  1. Add the role directly to the users table.
  2. Add a foreign key to the users table and have a roles table
  3. Use a pivot table to join the user and the role together.

Option 1 should only be used in a system with very few users.

id | username | role
-------------------------------------
1  | user1       | admin
-------------------------------------

Option 2 is for systems with many users

id | username | role_id
-------------------------------------
1  | user1       | 1
-------------------------------------

The role_id references the roles_table

id | role
---------------
1  | admin
---------------

Option 3 is for multi user systems with a possibility to let a user have multipple roles

Users table

id | username 
-------------------
1  | user1       
-------------------

roles table

id | role
---------------
1  | admin
---------------

role_users table

user_id| role_id
-------------------------------------
 1       | 1
-------------------------------------

The other upside to option 3 is that you can use the provided migrations and authentication out of the box.

Activity icon

Replied to Laravel Auth Middleware On Routes Testing With PHPunit

Try using this instead

/**
     * @test
     * @dataProvider protectedRoutesProvider
     * @param $method
     * @param $route
     */
    public function guests_are_redirected_to_login($method, $route)
    {
        $response = $this->$method($route);
        $response->assertLocation('/login');
    }

And the dataprovider

public function protectedRoutesProvider()
{
    return [
      'A guest is not authorized to visit the admin page' => ['get', '/admin'],
   ];
}
Activity icon

Awarded Best Reply on How Do Disable Foreign Key Checks In Tinker?

I'm guessing MySQL, this should most likely work.

Be aware that it's not a good practice to disable constraints. They are there to help you keep data concistency.

//Disable
DB::statement('SET FOREIGN_KEY_CHECKS=0;');

//Enable
DB::statement('SET FOREIGN_KEY_CHECKS=1;');

https://tableplus.com/blog/2018/08/mysql-how-to-temporarily-disable-foreign-key-constraints.html

Activity icon

Replied to How Do Disable Foreign Key Checks In Tinker?

I'm guessing MySQL, this should most likely work.

Be aware that it's not a good practice to disable constraints. They are there to help you keep data concistency.

//Disable
DB::statement('SET FOREIGN_KEY_CHECKS=0;');

//Enable
DB::statement('SET FOREIGN_KEY_CHECKS=1;');

https://tableplus.com/blog/2018/08/mysql-how-to-temporarily-disable-foreign-key-constraints.html

Jul
07
2 days ago
Activity icon

Replied to What Are Best Practices When Writing Tests With PHPUnit ?

Dataproviders is also a good tool to keep the tests cleaner

For example this test checks that a guest is redirected when trying to use any of the routes that needs a logged in user.

<?php

namespace Tests\Feature\Http;

use Tests\TestCase;

class AuthorizationTest extends TestCase
{
    public function protectedRoutesProvider()
    {
        return [
          'Artists: a guest is not authorized to visit the create page' => ['get', '/artists/create'],
          'Artists: a guest is not authorized to visit the edit page' => ['get', '/artists/1/edit'],
          'Artists: a guest is not authorized to visit the store page' => ['post', '/artists'],
          'Artists: a guest is not authorized to visit the update page' => ['put', '/artists/1'],
          'Artists: a guest is not authorized to visit the delete page' => ['delete', '/artists/1'],

          'Authors: a guest is not authorized to visit the create page' => ['get', '/authors/create'],
          'Authors: a guest is not authorized to visit the edit page' => ['get', '/authors/1/edit'],
          'Authors: a guest is not authorized to visit the store page' => ['post', '/authors'],
          'Authors: a guest is not authorized to visit the update page' => ['put', '/authors/1'],
          'Authors: a guest is not authorized to visit the delete page' => ['delete', '/authors/1'],

          'Books: a guest is not authorized to visit the create page' => ['get', '/books/create'],
          'Books: a guest is not authorized to visit the edit page' => ['get', '/books/1/edit'],
          'Books: a guest is not authorized to visit the store page' => ['post', '/books'],
          'Books: a guest is not authorized to visit the update page' => ['put', '/books/1'],
          'Books: a guest is not authorized to visit the delete page' => ['delete', '/books/1'],

          'Formats: a guest is not authorized to visit the create page' => ['get', '/formats/create'],
          'Formats: a guest is not authorized to visit the edit page' => ['get', '/formats/1/edit'],
          'Formats: a guest is not authorized to visit the store page' => ['post', '/formats'],
          'Formats: a guest is not authorized to visit the update page' => ['put', '/formats/1'],
          'Formats: a guest is not authorized to visit the delete page' => ['delete', '/formats/1'],

          'Genres: a guest is not authorized to visit the create page' => ['get', '/genres/create'],
          'Genres: a guest is not authorized to visit the edit page' => ['get', '/genres/1/edit'],
          'Genres: a guest is not authorized to visit the store page' => ['post', '/genres'],
          'Genres: a guest is not authorized to visit the update page' => ['put', '/genres/1'],
          'Genres: a guest is not authorized to visit the delete page' => ['delete', '/genres/1'],

          'Records: a guest is not authorized to visit the create page' => ['get', '/records/create'],
          'Records: a guest is not authorized to visit the edit page' => ['get', '/records/1/edit'],
          'Records: a guest is not authorized to visit the store page' => ['post', '/records'],
          'Records: a guest is not authorized to visit the update page' => ['put', '/records/1'],
          'Records: a guest is not authorized to visit the delete page' => ['delete', '/records/1'],

          'Tracks: a guest is not authorized to visit the create page' => ['get', '/tracks/create'],
          'Tracks: a guest is not authorized to visit the edit page' => ['get', '/tracks/1/edit'],
          'Tracks: a guest is not authorized to visit the store page' => ['post', '/tracks'],
          'Tracks: a guest is not authorized to visit the update page' => ['put', '/tracks/1'],
          'Trackss: a guest is not authorized to visit the delete page' => ['delete', '/tracks/1'],

          'BookCollection: a guest is not authorized to visit the store page' => ['post', '/bookcollections'],
          'BookCollection: a guest is not authorized to visit the delete page' => ['delete', '/bookcollections/1'],

          'BookRead: a guest is not authorized to visit the store page' => ['post', '/books/read'],
          'BookRead: a guest is not authorized to visit the delete page' => ['delete', '/books/read/1'],


        ];
    }

    /**
     * @test
     * @dataProvider protectedRoutesProvider
     * @param $method
     * @param $route
     */
    public function guests_are_redirected_to_login($method, $route)
    {
        $response = $this->$method($route);
        $response->assertLocation('/login');
    }
}
Jul
06
3 days ago
Activity icon

Awarded Best Reply on Oracle Update Query Not Responding

My guess is that something else is locking that record.

I suggest you try doing a select from update no wait skip locked then it will skip the update otherwise it will hang until the update is made.

http://www.dba-oracle.com/t_select_update_skip_locked.htm

You can run this to see what is locking your table

select * from DBA_DDL_LOCKS where name like :your_table;
Activity icon

Replied to Oracle Update Query Not Responding

My guess is that something else is locking that record.

I suggest you try doing a select from update no wait skip locked then it will skip the update otherwise it will hang until the update is made.

http://www.dba-oracle.com/t_select_update_skip_locked.htm

You can run this to see what is locking your table

select * from DBA_DDL_LOCKS where name like :your_table;
Activity icon

Replied to My Composer Is Very Slow In Importing The Pacakges

It sound to me that you have a very old computer and a really slow internet connection. I suggest you try closing as many applications as possible just to see if it runs a bit faster.

It might be that you have a shitload of processes running at the same time preventing the composer from running.

Jul
05
4 days ago
Activity icon

Replied to How To Encode Html Text And Display Decoded Html Text Correctly

As a rule of thumb, never ever use {!! $variable !!} unless you really can trusts the source and actually avoid it even if you can.

I'm guessing this is a blog or somewhere you allow tha user to input html into the database.

I would go with Markdown instead of html so I wouldn't have to worry as much about the user breaking the page.

Laravel by default escapes html before storing it in the table.

Activity icon

Replied to 404 Not Found

What happends if you change this line

$user = User::findOrFail($id);

To

$user = User::find($id);
dd($user);

Is the $user null or is it a user collection?

Activity icon

Replied to Save Exception In DB

Are you talking about storing the exceptions as a log or store the error messages in the database instead of in your code?

Activity icon

Replied to Image Once On The Left, Once On The Right

You use CSS for that just like you wold do for any webpage.

Activity icon

Replied to Axios Post Request Returns 404 On All Apis

Use the developer tools in your browser and check what uri it's giving the 404 on. It's most likely not pointing to the same uri as your postman request.

Activity icon

Replied to How To Return Name Of Grade When Save Like Json?

First of all I would never store a many to many relationship in a json field.

Store it in a pivot table instead then you can search and use aggregate functions on the data without any issues.

The pivot table can look something like this.

  • student_id
  • course_id
  • grade

I'm not a big fan of json columns at all since they kinda defeat the purpose of a relational database. They are also imho a shortcut to bad database designs.

Jul
04
5 days ago
Activity icon

Awarded Best Reply on [SOLVED] Laravel-firebird Package

According to the packagist page it does support Laravel 6 and 7.

https://packagist.org/packages/harrygulliford/laravel-firebird

I suggest you start here

https://github.com/harrygulliford/laravel-firebird

And if that doesn't help you show us some code and the error messages you have.

Activity icon

Replied to [SOLVED] Laravel-firebird Package

It seems that firebird does not allow boolean columns in the database or at least not with a default value. I suggest you change these two lines

$table->boolean('all_branch')->default(false)->comment('access all branch');
$table->boolean('is_active')->default(true);

To

$table->char('all_branch', 1)->default('0')->comment('access all branch');
$table->char('is_active', 1)->default('1');
Jul
02
1 week ago
Activity icon

Replied to [SOLVED] Laravel-firebird Package

According to the packagist page it does support Laravel 6 and 7.

https://packagist.org/packages/harrygulliford/laravel-firebird

I suggest you start here

https://github.com/harrygulliford/laravel-firebird

And if that doesn't help you show us some code and the error messages you have.

Activity icon

Replied to Email Is Taking So Much Time To Reach

Like I said that has nothing to do with the code. It all depends on the network and every server on the way from your server to the destination. Sometimes it can be fast other times slow. It all depends on the route it takes and how high the load is.

Activity icon

Replied to Email Is Taking So Much Time To Reach

That has nothing to do with the code it self. It depends on the network and the servers running.

Activity icon

Replied to How To Prevent From A Table Being Drop In Laravel

You say that you using dummy data, why not make sure you have a relationship and then try to drop it.

Jul
01
1 week ago
Activity icon

Replied to How To Prevent From A Table Being Drop In Laravel

I updated my previous reply since I was wrong in the effect of constraints when doing DDL.

Activity icon

Replied to Allowed Memory Size Of 1610612736 Bytes Exhausted (tried To Allocate 4096 Bytes)

Make sure that it is the cli php.ini you made the changes to and not the cgi php.ini used by your server.

Activity icon

Replied to How To Prevent From A Table Being Drop In Laravel

There are two different languages in SQL, DDL or Data Definition Language and DML or Data Manipulation Language. With DDL you create, alter, truncate and drop database objects (tables, views, indexes and such). With DML you read, insert, delete and update records in the database.

To prevent any object from being dropped you can create a user that only has SELECT, INSERT, UPDATE and DELETE on the tables in the database.

https://www.youtube.com/watch?v=HzZ3h-COam4

My bad. If there is a foreign key constraint and one record is referencing it you can't drop the table being referenced.

ERROR 1451 (23000): Cannot delete or update a parent row: a foreign key constraint fails

However you can drop the table that contains that foreign key.

Activity icon

Awarded Best Reply on Visual Studio Code Auto Completion

Have you tried felixfbecker.php-intellisense?

Activity icon

Awarded Best Reply on Windows 10 Global 'Homestead Up' Difficulty.

In the path variable you never specify the file name, just the directory that contains the file.

So this

C:\Batch\homestead.bat

Should be this

C:\Batch

That is of course if your files are in that directory.

Jun
30
1 week ago
Activity icon

Replied to Split A Page Into Multiple Pages Using Pagination

In your case I would use markdown for the blogposts then you can use something like this to find your page breaks.

<div style="page-break-after: always"></div>
Activity icon

Replied to Create Database On Live Server (heroku)

As the error message states you don't have the correct privileges to create a database.

If you want to move the data from one database to another you need to export it.

Not knowing what RDBMS you are using I can't point you to any guide on how to do that.

If it's just the database structure I recommend using Laravel migrations. If it's just a few tables with a few records in each that has default values use seeders for those.

Activity icon

Replied to How To Retrieve Column Comments ?

You can do something like this

\DB::select("SELECT COLUMN_COMMENT FROM INFORMATION_SCHEMA.COLUMNS WHERE  TABLE_SCHEMA = '<your database>' AND TABLE_NAME = '<your table>' AND COLUMN_NAME = 'your column'");
Activity icon

Replied to Why Vendor Folder Is Removed While Deploying To Elastic Beanstalk

When the deploy to the server is finished.

Activity icon

Replied to Why Vendor Folder Is Removed While Deploying To Elastic Beanstalk

Because after deploy you should run composer install to install all the dependencies,

Activity icon

Replied to How To Retrieve Column Comments ?

Yes you can retreive it but I wouldn't use comments in my application like that.

You can always just do a regular select on it.

Activity icon

Replied to Issue With Connecting To Database With Multiple Apps.

I'm guessing you are using MySQL 8 which has updated the security hash when it comes to passwords.

Try running this command in you database tool

ALTER USER username IDENTIFIED WITH caching_sha2_password BY 'YOUR_PASSWORD';
Activity icon

Replied to How To Retrieve Column Comments ?

Why would you want to do that?

What you could do is create a table called genders.

gender   | description
--------------------------------
m        | male
f        | female
o        | other

Then use the gender as the primary and foreign key in your table if you want a description of the abbriviation.

Jun
29
1 week ago
Activity icon

Replied to Windows 10 Global 'Homestead Up' Difficulty.

In the path variable you never specify the file name, just the directory that contains the file.

So this

C:\Batch\homestead.bat

Should be this

C:\Batch

That is of course if your files are in that directory.

Activity icon

Awarded Best Reply on How To Add A Column Comment In A Migration File ?

Just add the ->comment('my comment') in your migration file

$table->string('name')->comment('The full name of the user');

https://laravel.com/docs/7.x/migrations#column-modifiers

Activity icon

Awarded Best Reply on What's The Best Way To Avoid 2 000 000 Rows For A Table

imho = In My Humble Opinion.

With the proper indexes 1.6M rows is not a problem and from reading your description I find it highly unlikely that all 400 users customizes all of their elements.

If indexes shouldn't be enough you can partition the table.

Activity icon

Replied to What's The Best Way To Avoid 2 000 000 Rows For A Table

imho = In My Humble Opinion.

With the proper indexes 1.6M rows is not a problem and from reading your description I find it highly unlikely that all 400 users customizes all of their elements.

If indexes shouldn't be enough you can partition the table.

Activity icon

Replied to Visual Studio Code Auto Completion

Have you tried felixfbecker.php-intellisense?

Activity icon

Replied to How To Add A Column Comment In A Migration File ?

If you exchange the single quotes for double you should be able to do this.

$table->string('name')->comment("The full name of the user\nThis is row two");
Activity icon

Replied to Referencing Column Is Incompatible When Adding Foreign Keys

Then please mark the reply as best.

Activity icon

Replied to How To Add A Column Comment In A Migration File ?

Just add the ->comment('my comment') in your migration file

$table->string('name')->comment('The full name of the user');

https://laravel.com/docs/7.x/migrations#column-modifiers

Activity icon

Replied to Encrypt And Decrypt Name And First Name ?

Remeber that when you encrypt the database fields it will require decryption every time you access the values and it complicates things when you need to do basic searches in your queries. It will slow down your appliction.

Activity icon

Replied to Referencing Column Is Incompatible When Adding Foreign Keys

You foreing keys must be the same typr as the id they are referencing.

Change them to either foreign or unsignedBigInteger

$table->unsignedBigInteger("organization_id");
$table->foreignId("organization_id");

https://laravel.com/docs/7.x/migrations#foreign-key-constraints