Tray2

Tray2

Member Since 4 Years Ago

Solna

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

Experience Points 157,100
Experience Level 32

2,900 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 1124
Lessons
Completed
Best Reply Awards 83
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.

26 Jun
21 hours ago

Tray2 left a reply on Accordion Problem

That could be because you seem to be missing a closing </h2>

That css rule makes the link take up the whole space of it's container.

Tray2 left a reply on Accordion Problem

You change the CSS of the link by chenging the display propery to block.

.cars a {
   display: block;
}

or

add the class for it to your element.

Tray2 left a reply on Laravel In Ubuntu

If you use Ubuntu don't use XAMP, do it properly instead.

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

24 Jun
2 days ago

Tray2 left a reply on Separate Roles/permissions For Users Belonging To Multiple Organizations

You could use a many to many polymorphic relation for that

https://laravel.com/docs/5.8/eloquent-relationships#many-to-many-polymorphic-relations

You would have pivot table something like this

  • user_id
  • role_id
  • organization_id

Tray2 left a reply on Migrate:rollback Is Not Working When Test Stop

You should never need to use dd in a test unless you are debugging. There are assertions for about everything and you can write your own custom code to assert that a test gives the expected response or not.

Instead of ´dd´ you can use `var_du or `print that way you don't kill your execution.

23 Jun
3 days ago

Tray2 left a reply on Add Varieties To A Single Product

Something like pants, Lee. Levi's, Crocker and so on?

If so I would go with a categories table

id category

and a products table

id name category_id

Tray2 left a reply on Multiple Inputs Field Styling

Just pass the element to the JavaScript and then manipulte it.

Tray2 left a reply on GroupBy Not Working

I ran that query and got the following result.

mysql> SELECT b.released, GROUP_CONCAT(b.title) AS books
    -> FROM books b
    -> GROUP BY b.released;
+----------+-------------------------------------+
| released | books                               |
+----------+-------------------------------------+
|     1990 | The Eye Of The World,The Great Hunt |
|     1992 | The Dragon Reborn                   |
|     1993 | The Shadow Rising                   |
|     1994 | The Fires Of Heaven                 |
|     1995 | Lord Of Chaos                       |
|     1996 | A Crown Of Swords                   |
+----------+-------------------------------------+
6 rows in set (0,00 sec)

It grouped The Eye Of The World and The Great Hunt on 1990.

Tray2 left a reply on My Laravel Views Not Working

a2enmod is the one you use for enabling the mod_rewrite. Why not google for apache enable mod_rewrite ?

Tray2 left a reply on GroupBy Not Working

Something like this then?

SELECT b.year, GROUP_CONCAT(b.title) AS books
FROM books b
GROUP BY b.year;

Tray2 left a reply on My Laravel Views Not Working

On Linux and Mac

sudo a2enmod rewrite

Tray2 left a reply on Which OS Are You Using?

For Laravel macOS and Linus Ubnutu for other Wind0ze.

Tray2 left a reply on My Laravel Views Not Working

Have you enable the mod_rewrite module?

Tray2 left a reply on Laravel Testing

Well they should pass since you don't assert anythinh but the response status. You should also show us the code fore those methods.

This is my tests for for doing the same thing.

   /** @test */
    public function a_valid_author_can_be_stored()
    {
        $this->signIn();
        $this->withoutExceptionHandling();

        $author = factory(Author::class)->make([
          'first_name' => 'Robert',
          'last_name' => 'Jordan'
      ]);

        $response = $this->post('/authors', $author->toArray());

        $response->assertStatus(200);
        $this->assertEquals(1, Author::count());
    }


    /** @test */
    public function a_valid_author_can_be_updated()
    {
        $this->signIn();

        $this->withoutExceptionHandling();
        $author = factory(Author::class)->create([
            'first_name' => 'Steven',
            'last_name' => 'Jordan'
        ]);

        $author->first_name = 'Robert';

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



    /** @test */
    public function a_user_can_delete_an_author()
    {
        $this->signIn();

        $this->withoutExceptionHandling();
        $author = factory(Author::class)->create();
        $this->assertEquals(1, Author::count());

        $this->delete('/authors/' . $author->id);

        $this->assertEquals(0, Author::count());
    }
}

Tray2 left a reply on Laravel Explode Not Working

It would save you a lot of headache by storing the orders seperately instead of using stuff you don't really need. I suggest that you use the database for what it's best att instead of trying to do it in PHP.

Tray2 left a reply on Cascade Delete On Multiple Tables

Why not use the database to handle the deletions of the other tables?

$table->foreign('user_id')
      ->references('id')->on('users')
      ->onDelete('cascade');

Tray2 left a reply on GroupBy Not Working

To use a group by you need to have a statement that requires it like count or sum.

Not being sure what it is you want to achieve bot by looking at your query I think you want to sort the books by the year instead of group by.

$books = Book::orderBy('year', 'ASC')->get();
22 Jun
4 days ago

Tray2 left a reply on Only List Active Resources In Select Menu?

There is something called filters in Nova so you should probably use them instead of changing the code in the nova controllers.

https://nova.laravel.com/docs/1.0/customization/filters.html#overview

Tray2 left a reply on Only List Active Resources In Select Menu?

In the controller and method for the route you are hitting.

Tray2 left a reply on How To Order A Select The Checkboxes Product Only Once In Laravel?

Move

 if ($order) {
        alert()->error('Warning', 'You ordered already');
        return redirect()->back();
}

Above

    $order = new Order($request->all());
    $order->user_id = auth()->user()->id;
    $order->description = $request->description;
    $computer = implode(",", $request->computer);
    $order->computer = $computer;
    $order->save();

Other wise it will always create an order and then give you the error.

You can also check for an existing order in your validation rules then you don't need .

  $order = Order::where('user_id',auth()->id())
        ->where('computer', request('computer'))
        ->exists(); 

and

if ($order) {
        alert()->error('Warning', 'You ordered already');
        return redirect()->back();
    }

Tray2 left a reply on Multiple Inputs Field Styling

Copy what script?

Tray2 left a reply on Only List Active Resources In Select Menu?

You can probably change the query in the controller.

Resource::where('active', 1)->get();

Or something like it.

Tray2 left a reply on A Room Can Have Racks, But The ID Should Start From 1 For Each Room

I would not use the id as the rack number.

I would have a setup similar to this

Rooms

  • id
  • name

Rack

  • id
  • name
  • rack_number
  • room_id

That way you can number your rack anyway you want.

In the application I'm working with on my day job we have a larger scale setup like this

geographical_areas

  • address (unique number)
  • long_name (unique varchar)
  • pop_name
  • area_type
  • area_level

It contains any kind of area (property, zone, rack, section, compartment and so on. The we define the structure in

area_usages

  • address
  • used_address

That way the room address would be the address and the rack the used_address. You can then add sections to the rack but this time the rack is the address and the section is the used_address.

Tray2 left a reply on How To Make Animated Video Editing Or Animated Video Maker Tool? 3

This is not an easy thing to create from scratch.

You need a frontend that can create frames/images, Html canvas migth be an option. Then you need a backend to handle the submitted frames and convert them to a mp4 or similar. Laravel can handle the backend part and ffmpeg can convert the frames to a mp4.

Tray2 left a reply on Routing In Laravel?

And don't forget to enable the mod_rewrite.

Tray2 left a reply on Some Guideness For Laravel App

For a simple crud app you can do a test for validating the request.

Something like this can be your happy path

/** @test */
    public function a_valid_author_can_be_stored()
    {
        $this->signIn();
        $this->withoutExceptionHandling();

        $author = factory(Author::class)->make([
          'first_name' => 'Robert',
          'last_name' => 'Jordan'
      ]);

        $response = $this->post('/authors', $author->toArray());

        $response->assertStatus(200);
        $this->assertEquals(1, Author::count());
    }

Then you remove one of the values.

Something like

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

        $response = $this->post('/authors', $author->toArray())->assertSessionHasErrors(('first_name'));

        $this->assertEquals(0, Author::count());
    }

And so on.

Tray2 left a reply on Hoping For Some Assistance With A Possible Laravel Bug...

If you want to log what people are doing in the system I'd probably use triggers for that.

That way you will always log any kind of changes done in your tables regardless where they come from.

http://www.mysqltutorial.org/mysql-triggers.aspx

Tray2 left a reply on Hoping For Some Assistance With A Possible Laravel Bug...

So what is it you are trying to do?

Tray2 left a reply on Hoping For Some Assistance With A Possible Laravel Bug...

What is it you are trying to do?

What have you tried so far?

What is the expected result?

21 Jun
5 days ago

Tray2 left a reply on Multiple Inputs Field Styling

Yes and since you use classes you can add them to as many inputs as you like in your code.

If you are talking about not wanting to write the code for the element in your view multiple times you can use a foreach in your view as long as you pass an array of filed names.

$fields = ['field1', 'field2', 'field3'];
@foreach($fields as $field)
    <input type="file" name="{{ $field }}>
@endforeach

Tray2 left a reply on Multiple Inputs Field Styling

What is it you are trying to do?

Tray2 left a reply on Views Not Found In Res/views/projects/activity

Sure we can help as long as you give us something to see. No code usually means no help since we can't guess what it is you are trying to do.

Tray2 left a reply on Problem With Authentification

Show the controllers code.

Tray2 left a reply on WhereNotIn & Where Methods Not Working When Combined

So you are saying that something like

$records = Record::where('artist_id', $id)->whereIn('format_id', [1, 2, 3])->get();

Isn't working?

Tray2 left a reply on Problem With Authentification

Add

use App\User; 

To the file where the rest of the usestatements are.

Tray2 left a reply on Best Practice To Implement Code Revision

I would do Local Git Repository -> Github -> Production Server.

20 Jun
6 days ago

Tray2 left a reply on SQLSTATE[42S22]: Column Not Found: 1054 Unknown Column 'issuer' In 'field List'

The issue is that you are trying to insert into your warnings table and in it you have an issuer_id but the code you have issuer which does not exist.

Try changing this line

$player->warnings()->create(
            [ 'message' => $faker->text, 'issuer' => $player ]
        );

to

$player->warnings()->create(
            [ 'message' => $faker->text, 'issuer_id' => $player ]
        );

Tray2 left a reply on Versioning

Git is you friend for that.

Tray2 left a reply on Best Practice To Run Artisan Commands With Docker?

If you can't SSH into the server then you can create an alias for it in your bash_profile or bashrc

alias dmm='docker-compose exec app php artisan make:controller'

so

docker-compose exec app php artisan make:controller MyController

Would become

dmm MyController
19 Jun
1 week ago

Tray2 left a reply on Using Transactions In Laravel User::Create For Setting User Role

You use User::create which creates the user then you use $this->create($data); which probably does the same thing.

Tray2 left a reply on Render Button

Not sure what you are trying to do here but conditional renderings serverside needs to be done with a request.

So if you have something like

<form method="POST" action="someurl">
    <input type="radio" id="render">
    <input type="radio" id="norender">
    <input type="submit"> 
</form>

Then you can take the request and check if render is checked.

You must do this with a request since the rendering is done serverside.

If you want it without reloading the page you need to use javascript and or css.

Tray2 left a reply on Using Transactions In Laravel User::Create For Setting User Role

Have you added the use DatabaseTransactions; in your controller?

18 Jun
1 week ago

Tray2 left a reply on Does Eloquent Insert/save Check Any FK Relations Exist

No it doesn't. If you have defined a foreign key constraint in the database and you are trying to insert a value that does not exist in the table you reference it will give you an error.

You should validate the foreign key in you controller so that it will fail if it's missing.

Use the existsvalidation rule

https://laravel.com/docs/5.8/validation#rule-exists

Tray2 left a reply on Multiple Clicking On Submit Button

I guess you are using JavaScript and Ajax to send the request.

Then you can disable the button after the first pressing so it can't be submitted more than once.

document.getElementById("idOfButton").onclick = function() {
    //disable
    this.disabled = true;

    //do some validation stuff
}