Tray2

Tray2

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

Member Since 5 Years Ago

Solna

Experience Points
240,600
Total
Experience

4,400 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
1266
Lessons
Completed
Best Reply Awards
179
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 49
240,600 XP
Feb
19
21 hours ago
Activity icon

Replied to Is Mixing Javascript With Blade Syntax A Bad Practice?

In some cases it migth be necessary to have javascript in you view code but most of the time it's best to keep it in a dedicated js file. Just like @sinnbeck says use the regular script tag since there is no need to get fancy. If you want to have page specific javascript on just that page you can use yield in you master template file and then pass that in with the section in your view.

Master

<html>
    <head>
        <title>App Name - @yield('title')</title>
    </head>
    <body>
        <div class="container">
            @yield('content')
        </div>
    @yield('page_specific_js')
    </body>
</html>

View

@section('page_specific_js')
    <script src="js/onlyhere.js"></script>
@endsection
Feb
18
1 day ago
Activity icon

Replied to Why The Parameter For This Function Be The Key For The Array Posts ?

What the heck are you trying to do?

Feb
17
2 days ago
Activity icon

Replied to Checking For Broken Pages And Links

One way is to use tests for that. I'm using a test like this to check that all the routes that reqiures a logged in user does just that.

    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'],
    ];
}

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

Something like that shouls be quite easy to adapt to your purpose.

Activity icon

Replied to How To Group Several Routes In Order To Be Handled By Single Controller Method

I would to these

Route::post('/weight', 'BioData\[email protected]');
Route::post('/shoulder', 'BioData\[email protected]');
Route::post('/waist', 'BioData\[email protected]');

as

Route::post('/biodata/{measurePoint}', 'BioData\[email protected]');

or just pass it along in the request

Route::post('/biodata', 'BioData\[email protected]');

Nice and DRY

Feb
16
3 days ago
Activity icon

Replied to Eloquent Vs. Custom Query

Like everything when it comes to SQL you need to write good code. A badly written query is slow regardless if it's done in Eloquent, Query builder or just plain SQL.

As a rule of thumb I use Eloquent if the query is not that complex like a simple select with a where and order by clause.

$records = Record::where('aritst_id', 1)->orderBy('title')->get();

If I need to join more than two tables together I usually push the query into the database so I can still use Eloquent in my controller.

In the example below the Artist, Genre and Format table is joined in the view in the database.

$records = RecordView::where('artist', 'Run Dmc')->orderBy('title')->get();

The biggest reason I don this is that I'm more comfortable with SQL than Eloquent and like to keep my eloquent queries KISS.

Activity icon

Replied to Resize And Optimize Images Upon Upload With Laravel Filemanager

I use intervention for that. Then resize it before it's moved from the upload folder.

https://www.webslesson.info/2019/09/how-to-upload-resize-image-in-laravel-5-8.html

Activity icon

Replied to What Is The Difference Of Unit Test And Feature Test

Yes those are not part of standard Laravel.

The $this->createForeignKeys(); is a method that creates all the necessary foreign keys for that and other tests. I didn't want to use the regular setUp()method since I don't want them in all my tests in that test class.

The this->signIn() method creates a user and signs that user in. Jeffrey uses that one in a couple of his series on TDD.

assertSee is a Laravel specific assertion just like @sinnbeck stated.

Activity icon

Replied to Multiple Data Input Form

Show us the code that generates the error.

Activity icon

Replied to What Is The Difference Of Unit Test And Feature Test

A unit test should just test one method like checking that a sum method returns the sum of two numbers while a feature test can test the functionality of a chain of methods.

Unit test example

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

        $this->assertEquals('Jordan, Robert', $author->name);
    }

Feature test example

    /**
    * @test
    */
    public function when_users_update_a_book_they_are_redirected_to_the_book_index_and_are_shown_a_success_message()
    {
        $this->createForeignKeys();
        $this->signIn();
        $book = factory(Book::class)->create();
        $book->title = 'Kalle';

        $response = $this->patch('/books/' . $book->id, $book->toArray());

        $response->assertStatus(302);
        $response->assertLocation('/books');

        $response = $this->get('/books');
        $response->assertSee(e($book->title) . ' successfully updated.');
    }
Activity icon

Replied to How Do I Check If The 'slug' Is Unique Across All Tables With 'slug' Column?

Do they really need to be unique?

If you have routes like

Route::get('/model1/{slug}', '[email protected]');

Route::get('/model2/{slug}', '[email protected]');

They don't have to be unique.

If you really want then to be unique you can have a slugs table and you have a slug_id in your other tables.

Activity icon

Replied to Check In Blade, Is It Iframe Exist

Not sure why you would use an iframe for that at all and not sure what you mean by correct iframe either.

But if you have several of these iframes you just change the url for them to get what you need.

 <iframe src="https://yoursite.com/links/utils"></iframe>

 <iframe src="https://yoursite.com/links/applcations"></iframe>  

But I think iframes is a bad choice since it needs to do more requests to the server. It's better to do a partial that you can reuse multiple times while still on the serverside.

This tutorial covers that in a clever way https://laracasts.com/series/javascript-techniques-for-server-side-developers/episodes/1

Feb
15
4 days ago
Activity icon

Replied to Selecting Using Test In Model

You can always extract the Share::where to a function

protected function sharedAlbums()
{
    return Share::where('user_id', Auth::user()->id)->pluck('album_id')->toArray(); 
}

then call it like this

$albums = Album::whereIn('id', $this->sharedAlbums())->get();

Activity icon

Replied to Selecting Using Test In Model

Not sure what it is you are trying to do but if you want the user only to see albums that that is shared with the user I would do something like.

$albums = Album::whereIn('id', Share::where('user_id', Auth::user()->id)->pluck('album_id')->toArray())->get();
Feb
10
1 week ago
Activity icon

Replied to Installing Laravel Is A &^$%#HELL

@sinnbeck True but wouldn't that also be true with 755, since when you hit that file it's run as www-data?

Activity icon

Replied to Installing Laravel Is A &^$%#HELL

@sinnbeck You are correct but for the storge folder it's no biggie imho.

@bruin Well I wouldn't worry too much about that 777 on that folder.

Activity icon

Replied to Request For Advice: Migrating Data From Old Database

That is in step 3, you use SQL to store the data in the new tables.

For example this would extract all the authors from a books table and insert them into a new one

INSERT INTO authors (first_name, last_name)
SELECT DISTINCT first_name, 
                                last_name 
FROM books_old;

Then you can extract the rest of the book into the new books table.

INSERT INTO books (title, released, series, part)
SELECT title,
          released,
          series,
          part
FROM books_old;

And so on.

https://www.w3schools.com/sql/sql_insert_into_select.asp

Activity icon

Replied to Installing Laravel Is A &^$%#HELL

You should never use sudo when running composer. All the files it generates belongs to root if you do and www-data can't read them.

To get it working you need to sudo chown -R www-data:www-data /var/www/<your-site>then you need to `sudo chmod -R 755 /var/www/<your-site>/storage

It's better to remove the folder and then create new Laravel project.

Updated to 755 since it's "bad" practice.

Activity icon

Replied to Installing Laravel Is A &^$%#HELL

I've followed that guide myself without any issues.

What user are you logged in as?

Have you done sudo su?

Just ran the command on my server and no issue.

Activity icon

Replied to Request For Advice: Migrating Data From Old Database

I would probably do something like this

  1. Make a copy of the database as is
  2. Create new tables for everything according to the new schema
  3. Transfer the old data to the new tables
  4. Drop the old tables
  5. Rename the new tables to the names in the schema
  6. Export the database as SQL
  7. Import the data into the new database.

I would do this using SQL and not involve Laravel if I can help it.

Feb
09
1 week ago
Activity icon

Replied to Dynamic Href Tag With Id

You should never mix <button>and <a> in the same tag.

Activity icon

Replied to Large Data

I would go with MySQL or MariaDB since they are supported out of the box by Laravel or maybe Postgres.

Activity icon

Replied to Sum Total Of Column

Have you put use App\User; in your uses section?

Example on how it can look

<?php

namespace App\Http\Controllers;

use App\User;
use Illuminate\Http\Request;


I noticed you use it in your blade file then you need to

{{App\User::all()->sum('shares')}}

I try not to use Eloquent in the view if I can avoid it.

Activity icon

Replied to Will Running Schema On Model To Update Or Create Table Everytime Slow Down Application?

You really should put that in a migration instead so you can do a php artisan migrate once when you update.

Yes it will affect the performance but not that much but it's unecessary code that does not belong in production code.

Activity icon

Replied to Sum Total Of Column

The Model is the table name in singular.

So if you have a table called users and a column named age you use

User::all()->sum('age');
Feb
08
1 week ago
Activity icon

Replied to How Can I Develop My Programming Skill?

Watching the videos here is a good start.

There is also a good book by Matt Stauffer https://www.programmer-books.com/laravel-up-and-running-pdf/

Tighten also has lots of good tips in their blog https://tighten.co/blog/

Adam Wathan's Test Driven Laravel is a good course on testing. https://course.testdrivenlaravel.com/

Jason McCreary's Confident Laravel is another great course https://confidentlaravel.com/

Uncle Bob (Robert C. Martin) has some good books on clean code that is really good https://www.amazon.com/Clean-Code-Handbook-Software-Craftsmanship-ebook/dp/B001GSTOAM and a site with tutorials dedicated to clean code https://cleancoders.com/

Good luck.

Ooh and I almost forgot. Practice, practice, practice, practice and practice, practice, practice and practice.

Activity icon

Replied to Display Selected Record Information From Select Option

You can do it with vanilla javascript or jquery or any other javascript library you want.

In vanilla it would look something like

document,querySelector('#select').addEventListner('change', getProductInfo());

function getProductInfo() {
    fetch('http://example.com/products/' + document.querySelector('#select').selectedIndex)
  .then((response) => {
    return response.json();
  })
  .then((myJson) => {
    document.querySelector('#product_name').innerHTML = myJson.name;
  });
}
Feb
07
1 week ago
Activity icon

Replied to Best Code Editor For Laravel

There is always Netbeans and Eclipse for a more IDE feeling and both are free.

Activity icon

Replied to How Can I Get Device Name Or Any Unique Value In Device ?

The only way to to that is to create a app for the specific device so that each installation get it's own unique id. Doing that for a browser is impossible since it's quite easy to spoof that information.

Feb
06
1 week ago
Activity icon

Awarded Best Reply on Laravel Can Do This? If Can Any References?

Yes it can since that is regular HTML with a bit of javascript. However I recommend using a plugin like the ckeditor, tinyMCE or similar

https://ckeditor.com/

https://www.tiny.cloud/

Activity icon

Replied to Laravel Can Do This? If Can Any References?

Yes it can since that is regular HTML with a bit of javascript. However I recommend using a plugin like the ckeditor, tinyMCE or similar

https://ckeditor.com/

https://www.tiny.cloud/

Activity icon

Replied to Access Nested Object

What is the exact json structure of the response?

Feb
05
2 weeks ago
Activity icon

Replied to Add 1 Year In Today's Date Default In Database

Your solution is what I would go with

\Carbon\Carbon::now()->addYear()

I would import the carbon namespace though.

Activity icon

Awarded Best Reply on Tips For Database Design

I would have one invites table and then have a type field that tells what kind of invite it is. If I then need to connect some foreign key I just add that so the table could look something like

  • id
  • invitation
  • type
  • type id

That way it doesn't matter what model has created the invite when you do a serach like /invite/123.

Activity icon

Replied to Using New Mysqli In Laravel

You can use anything that php allows in Laravel like mysqli but the question is why would you like to use it. PDO is much safer and unless you do some fancy SQL then I suggest you stick to Eloquent or the query builder.

Activity icon

Replied to Tips For Database Design

I would have one invites table and then have a type field that tells what kind of invite it is. If I then need to connect some foreign key I just add that so the table could look something like

  • id
  • invitation
  • type
  • type id

That way it doesn't matter what model has created the invite when you do a serach like /invite/123.

Feb
04
2 weeks ago
Activity icon

Replied to Allowed Memory Size Exhausted

Then you are doing something strange in your code cause a 1:1 relation should never run out of memory. I suggest you install Telescope and then check how many times that query is hit. I'm guessing a lot.

https://laravel.com/docs/6.x/telescope

Activity icon

Replied to Allowed Memory Size Exhausted

It's simple math.

When you pull in all relations you run out of memory. You can try chunking the results

https://laravel.com/docs/6.x/eloquent#chunking-results

Activity icon

Replied to Dynamic Database When User Login

That my friend is a really bad idea.

You only need one database, just make sure that you have a user_id in each of your tables then you will have the same end result as a database per user.

The only reason that I can see to keep them in seperate databases is if you have absurdly large data in the tables and lots of traffic but then maybe you shouldn't use a single app but rather one for each user/set of users.

Activity icon

Awarded Best Reply on Database Migrate Error

This row

class phpCreateRoleUserPivotTable extends Migration

should be

class CreateRoleUserPivotTable extends Migration
Activity icon

Replied to Database Migrate Error

This row

class phpCreateRoleUserPivotTable extends Migration

should be

class CreateRoleUserPivotTable extends Migration
Activity icon

Replied to Database Migrate Error

Show us your create_role_user_pivot_table migration.

Activity icon

Replied to SQL

No you can't.

There are different ways to do something like that depending on what database you are running.

For MySQL you can do this

select table_schema as database_name,
    table_name
from information_schema.tables
where table_type = 'BASE TABLE'
    and table_schema not in ('information_schema','mysql',
                             'performance_schema','sys')
order by database_name, table_name;
Feb
03
2 weeks ago
Activity icon

Replied to Opening Times, Save To Db Correctly....

I would have a table called opening_hours or similar where I would store all the opening hours.

It would look something like this

  • id
  • day
  • open
  • close
  • store_id

So if the day does not have any entry == closed.

Feb
01
2 weeks ago
Activity icon

Replied to Ajax File Upload Form - Call To Member Function Extension Null

Do a dd($request); and share what it contains. There you should be able to see if there is a file or not.

Activity icon

Replied to PHP Array Help

Are you using Laravel or plain PHP?

The collection method is a helper in Laravel so if you are using plain PHP the collection helper is not available.

https://laravel.com/docs/6.x/collections

Activity icon

Replied to SQLSTATE[42S22]: Column Not Found: 1054 Unknown Column 'pending_payment' In 'where Clause

I would write that in plain SQL instead of Eloquent but give this a try, it might work.

$payments = User::where('users.status',1)
           ->join('link_clicks','users.id','=','link_clicks.user_id')
           ->whereDate('link_clicks.created_at','<',Carbon::now()->startOfMonth())
           ->leftJoin('payments','users.id','=','payments.user_id')
           ->where('payments.status',1)
           ->where(DB::raw('sum(link_clicks.earn) as total_earn','sum(payments.paid) as total_paid','ABS(total_earn-total_paid),'>=',10)->groupby('users.id')->paginate(10);
Activity icon

Replied to Migration Error On Unit Test Run

Try changing this line

<server name="DB_CONNECTION" value="sqlite_testing"/>

to

<server name="DB_CONNECTION" value="sqlite"/>