Tray2

Tray2

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

Member Since 5 Years Ago

Solna

Experience Points
251,540
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
1290
Lessons
Completed
Best Reply Awards
191
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
251,540 XP
Apr
01
16 hours ago
Activity icon

Replied to Syntax Error, Unexpected End Of File

In my opinion yes. You should almost always match the model with a controller.

Activity icon

Awarded Best Reply on Difference Between Queries?

My guess is that the first one gives you a cartesian product and the other doesn't.

That basically means that you have duplicates in the first query. It adds all records together regardless of the where clause.

However that is just a guess.

Activity icon

Replied to Using Sanctum With A Vue SPA

The cors issue is what you get when using localhost. You need to use a proper domain for ajax.

Mar
31
1 day ago
Activity icon

Replied to Laravel 6 + Apache = Takes Almost All Memory

That looks to me like you really need to use the database for what it's made to do instead of using php to process the results.

Simplified example:

PHP side processing

$games = Game::all();
foreach($games as $game) {
	if($game->title == 'Quake') {
		//do something
	}
}

SQL side processing

$game = Game::whereTitle('Quake')->get();
//do something

The first example would most likely generate an 500 error if you have thousands of games in your table and use up way more memory then necessary.

The second example would use the RDBMS to get the data in an efficient memory lean way.

Activity icon

Replied to Laravel - Take 20 Rows Of The Latest Posts And Then Order By Column2

This would work as well

App\Post::latest()->limit(20)->orderBy('views', 'desc')->get();

And if it gets slow you can do

App\Post::latest()->limit(20)->orderBy('views', 'desc')->toSql();

Then you can run explain on your query to see where you need to add your indexes.

Your SQL would look like this

select * from `posts` order by `created_at` desc, `views` desc limit 20;

And with the explain it would look like this

explain select * from `posts` order by `created_at` desc, `views` desc limit 20;

And the result something like this

+------+-------------+---------+------+---------------+------+---------+------+------+----------------+
| id   | select_type | table   | type | possible_keys | key  | key_len | ref  | rows | Extra          |
+------+-------------+---------+------+---------------+------+---------+------+------+----------------+
|    1 | SIMPLE      | posts | ALL  | NULL          | NULL | NULL    | NULL | 3    | Using filesort |
+------+-------------+---------+------+---------------+------+---------+------+------+----------------+

Look for full table scan and try adding indexes to remove those.

Mar
30
2 days ago
Activity icon

Replied to Difference Between Queries?

My guess is that the first one gives you a cartesian product and the other doesn't.

That basically means that you have duplicates in the first query. It adds all records together regardless of the where clause.

However that is just a guess.

Activity icon

Replied to 404 Error When I Use FormRequest

So you are making a post request to https://somedomain.com/auth/register ?

Are you passing a valid CSRF token?

Activity icon

Replied to Still No Love For MongoDB?

Relational databases will probably never be obsolete but rather there is a time and place for everything.

https://www.integrant.com/when-to-use-sql-vs-nosql/

There are several packages for MongoDB already

https://medium.com/@alexrenoki/when-to-use-nosql-getting-started-with-mongodb-in-laravel-f5376ceaf545

https://github.com/jenssegers/laravel-mongodb

Activity icon

Replied to Didn't Understand Actual Mean Of Singleton , Anybody Can Explain Me ?

A singleton is mostly used instead of application wide global variable.

Activity icon

Replied to Can I Use QR Code To Scan And Update The Order Status?

A regular browser in the phone would be enough and the need to be signed in isn't mandatory. Though most courier firms have their own system to track shipments.

Activity icon

Replied to 404 Error When I Use FormRequest

Show us your routes, controller and blade file.

Activity icon

Replied to Can I Use QR Code To Scan And Update The Order Status?

In short yes it's doable.

The Qr code needs to contain a link to your finish order route with a uuid or similar that puts the order into finish state. You can use something similar to how Laravel handles the reset password link.

Mar
29
3 days ago
Activity icon

Replied to Laravel New Blog Throughs Error Copy() Failed To Open Stream Permission Denied

Since you are on a mac use Laravel Valet instead of mamp.

https://laravel.com/docs/7.x/valet#introduction

Then you can use a path like the one above.

Activity icon

Replied to Laravel New Blog Throughs Error Copy() Failed To Open Stream Permission Denied

Where are you installing it?

You should create a folder in your home directory for it something like

/Users/<user>/Code

And in it create your project.

Mar
28
4 days ago
Activity icon

Replied to Undefined Variable Posts In My Website (urgent)

Is the index file named ├Čndex.blade.php`?

Activity icon

Replied to After Executing The Tests Tables Are Removed

Then the test isn't using the phpunit.xml for some reason.

Activity icon

Replied to After Executing The Tests Tables Are Removed

What happens if you comment out all the sqlite settings in your .env file?

//DB_CONNECTION=sqlite   <--
//DB_HOST=127.0.0.1
//DB_PORT=3306
//DB_DATABASE=/home/my/path/db.sqlite   <--
//DB_USERNAME=root
//DB_PASSWORD=

And run the tests again?

Activity icon

Awarded Best Reply on Laravel Installing Won't Install On Local Server

Try

composer create-project laravel/laravel somedir

Activity icon

Replied to Laravel Installing Won't Install On Local Server

It tells composer what to download

Activity icon

Replied to Laravel Installing Won't Install On Local Server

Try

composer create-project laravel/laravel somedir

Activity icon

Replied to Laravel Installing Won't Install On Local Server

Do you have the right php version installed?

php --version should give version 7.3 or above.

Activity icon

Replied to After Executing The Tests Tables Are Removed

If you run ./vendor/bin/phpunit does it still empty your sqlite db?

Activity icon

Replied to PHP OOP Book

I liked the PHP Object-Oriented Solutions by David Powers isbn 9781430210115

https://www.goodreads.com/book/show/4479421-php-object-oriented-solutions?ac=1&from_search=true&qid=WsFW57sM0N&rank=1

Activity icon

Replied to After Executing The Tests Tables Are Removed

Then the test isn't using the phpunit.xml file but rather your .env file.

Are you sure the sqlite :memory: is ser in your phpunit.xml?

Are you running phpunit in the root of your project?

<server name="APP_ENV" value="testing"/>
<server name="BCRYPT_ROUNDS" value="4"/>
<server name="CACHE_DRIVER" value="array"/>
<server name="DB_CONNECTION" value="sqlite"/>
<server name="DB_DATABASE" value=":memory:"/>
<server name="MAIL_MAILER" value="array"/>
<server name="QUEUE_CONNECTION" value="sync"/>
<server name="SESSION_DRIVER" value="array"/>
Activity icon

Replied to After Executing The Tests Tables Are Removed

When using an Sqlite in memory database and database mirgrations it does the following

  1. Migrate the database
  2. Perform the test
  3. Rollback the database migration done before the test.

PHPUnit uses the phpunit.xml file to know which database to use and it does in your case don't use the one you specified in your .env file. To be able to log in using your browser you need to run php artisan migrate and then add a user so that you can use that to log in.

Mar
26
6 days ago
Activity icon

Replied to Loading Time - Website

I would check all the database queries and see if that some indexes are needed. You can use the laravel debubar for this or telescope.

Mar
25
1 week ago
Activity icon

Replied to Laravel 6 - TDD App - Table Includes App\Task As Subject_type?

You are probably refering to the Task instance instead of the task->id somewhere but it's hard to guess since you don't share your code.

Activity icon

Replied to I Have Error In The Migration Table Please Urgently I Will Lost My Work

@click In most languages an assignment is always true. It might not be so in PHP but then again I would never write an assignment in an if statement since it's very hard to read.

Activity icon

Replied to Integer Length In Migration

You can use these

https://laravel.com/docs/7.x/migrations#columns

In short

$table->bigInteger()
$table->mediumInteger()
$table->integer()
$table->smallInteger()
$table->tinyInteger()
Activity icon

Replied to I Have Error In The Migration Table Please Urgently I Will Lost My Work

Not sure what you are trying to do but this row will always be true

if($files=$request->file('images')){
Mar
22
1 week ago
Activity icon

Awarded Best Reply on Javascript Not Working ( I Am New To It )

Javascript is case sensitive so you must use exactly the same case on the function call and the declaration.

Change

<select onclick="readonly()" class="form-control" id="exampleFormControlSelect1">

to

<select onclick="readOnly()" class="form-control" id="exampleFormControlSelect1">
Activity icon

Replied to Javascript Not Working ( I Am New To It )

Javascript is case sensitive so you must use exactly the same case on the function call and the declaration.

Change

<select onclick="readonly()" class="form-control" id="exampleFormControlSelect1">

to

<select onclick="readOnly()" class="form-control" id="exampleFormControlSelect1">
Activity icon

Replied to PHPUnit: Authentication

I do this in my tests.

In the TestCase.php I add the following method

    protected function signIn($user = null)
    {
        $user = $user ?: factory(\App\User::class)->create();
        $this->actingAs($user);
        return $this;
    }

Then on every test that needs an authenticated user you add the following line

$this->signIn();

Jeffrey uses this technique as well in the TDD courses as well.

Mar
21
1 week ago
Activity icon

Replied to Configuration Laravel Apache2 Host On Debian RapsberryPi

Have you run the a2enmod rewrite command?

Activity icon

Awarded Best Reply on Setup In Ubuntu Only Shows Index.php As Text

PHP is probably not installed or not configured correctly.

I suggest you follow this guide on ho to setup an Ubuntu lamp stack.

https://www.howtoforge.com/tutorial/install-apache-with-php-and-mysql-on-ubuntu-18-04-lamp/

Or this one that is specially for Laravel

https://www.howtoforge.com/tutorial/install-laravel-on-ubuntu-for-apache/

Mar
20
1 week ago
Activity icon

Replied to Validation Of Many Fields

You can make them have the same name like this

<input type="checkbox" name="day[monday]">
 <input type="checkbox" name="day[tuesday]">
 <input type="checkbox" name="day[..]">

Then you can validate that it is an array that has been passed.

'day' => 'required|array',
Activity icon

Replied to SQL Native To Query Builder

@emfinanga Don't reopen old solved threads. Create a new thread instead. Also you should wrap your code in three backticks to make it more readable.

//Code goes here
Activity icon

Replied to Trying To Paginate (Call To Undefined Method App\Post::links())

Change this line

$post = $user->post()->latest()->paginate(15);

To

  $user = $user->post()->latest()->paginate(15);

It overwrites the first one. And then change

<?php echo $post->links('cpag.custom'); ?>

To

<?php echo $user->links('cpag.custom'); ?>
Activity icon

Replied to Unique Request Rules Allows Duplicate

You can use the unique rule with multiple fields like this

 'first_name' => 'required|unique:authors,first_name,' . null . ',id,last_name,'. $request->last_name,

And use SQL do use multiple fields as unique

ALTER TABLE `votes` ADD UNIQUE `unique_index`(`user`, `email`, `address`);

Activity icon

Replied to Need Help Converting Complex MySQL Query

This is not one query it's multiple queries:

//Q1
LOCK TABLES nested_categories WRITE;

//Q2
SELECT @myRight := rgt FROM nested_categories
WHERE name = 'Root';

//Q3
UPDATE nested_categories SET rgt = rgt + 2 WHERE rgt > @myRight;

//Q4
UPDATE nested_categories SET lft = lft + 2 WHERE lft > @myRight;

//Q5
INSERT INTO nested_categories(name, lft, rgt) VALUES('Materials', @myRight + 1, @myRight + 2);

//Q6
UNLOCK TABLES;

The reason the work in the console is that they are handled as six seperate queries but what you tried to do is run it in Laravel which tries to parse it into one query thus failing.

I would use database transactions for this and use SELECT FOR UPDATE

https://dev.mysql.com/doc/refman/5.6/en/innodb-locking-reads.html

Activity icon

Replied to Setup In Ubuntu Only Shows Index.php As Text

PHP is probably not installed or not configured correctly.

I suggest you follow this guide on ho to setup an Ubuntu lamp stack.

https://www.howtoforge.com/tutorial/install-apache-with-php-and-mysql-on-ubuntu-18-04-lamp/

Or this one that is specially for Laravel

https://www.howtoforge.com/tutorial/install-laravel-on-ubuntu-for-apache/

Mar
19
1 week ago
Activity icon

Awarded Best Reply on Laravel Unique Validation Rule

I have done this in my app Where the combination between the first and the last name of an author must be unique.

'first_name' => 'required|unique:authors,first_name,' . null . ',id,last_name,'. $request->last_name

It should be quite easy for you to change the name of the fields to suit your needs.

Mar
18
2 weeks ago
Activity icon

Replied to Trying To Displaying AJAX JSON Return But Get "undefined"

A bit simplified

  1. Get the json data from the end point
  2. Parse the json response
  3. Display the json response
const response = getRequest('<url>');
const jsonResponse = JSON.parse(response);

document.querySelector('#title').value = jsonResponse.title;

The old way

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

The new way with the fetch api

https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch

Mar
16
2 weeks ago
Activity icon

Replied to Laravel Unique Validation Rule

@ahmednaser Mark one of the as best reply to show that the thread is solved :)

Mar
15
2 weeks ago
Activity icon

Replied to Laravel Unique Validation Rule

I have done this in my app Where the combination between the first and the last name of an author must be unique.

'first_name' => 'required|unique:authors,first_name,' . null . ',id,last_name,'. $request->last_name

It should be quite easy for you to change the name of the fields to suit your needs.