Tray2

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

Member Since 6 Years Ago

Solna

Experience Points
407,960
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
1567
Lessons
Completed
Best Reply Awards
367
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.

  • Community Pillar

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

Level 50
407,960 XP
Jan
21
8 hours ago
Activity icon

Replied to How To Create An App Like Netflix And How Much Does It Cost?

That was exactly what I was refering to when I menat that the security is the tricky part :)

Activity icon

Replied to Avoid Duplication

Yes, but which of the ones do you get duplicates from?

You really should TDD this stuff.

Activity icon

Replied to How To Create An App Like Netflix And How Much Does It Cost?

You should use TDD to do it.

An application like that isn't really that complex to build.

You need a media host that handles the streaming with a shitload of bandwidth and discspace.

The rest is a regular CRUD application for the web and a app for iOS, Android and all the Smart-TV brands out there.

Then you need to handle security to prevent downloading of the movies which hopefully the media host can provide. Then you need to handle subscriptions and max no of connections per user and so on. The payment you can handle with cashier. With Jetstream you have a lot of user handling built in.

The security will be the trickiest part.

Activity icon

Replied to Cannot Use Table Alias When Using Soft Deletes.

That is incorrect.

this is allowed.

SELECT p.* 
FROM products p 
WHERE p.description like 'E%'

What they are refereing to is a query like this

SELECT title, count(*) AS quantity
FROM products
WHERE quantity = 10 
GROUP BY title

Then you are not allowed to use the alias in the where clause.

Activity icon

Replied to Avoid Duplication

Change this

  foreach ($no as $idnx) {
                $noo = (int) $idnx->bill_no;
            }

            $tambah = $noo + 1;

To this

  $tambah = (int) $no->bill_no + 1;

Now which path does it take in the if statement?

 if ($request->slave_ID) {
      foreach ($request->slave_ID as $key => $value) {
        $data['slave_id'] =$request->slave_ID[$key],
        Sales::create($data); 
      }

    }else{
      $data['slave_id'] = ($request->has('slave_ID') && count($request->slave_ID) > 0)? count($request->slave_ID) : null;
      Sales::create($data); 
    }
Activity icon

Replied to Avoid Duplication

Ah duplicates in the database I thought it was duplicate code.

Anyway my code made it cleaner :)

So what you want to do is pad the bill_number.

E210120210001
E210120210099
E210120210999
E210120211001
E210120211002

You can use str_pad for that

$bill_number = 'E' . Carbon::now()->format('dmy') . str_pad($tambah, 4, '0', STR_PAD_LEFT);

Instead of using the if statement.

This is probalby the issue

 $no = DB::select("SELECT max(right(bill_number,4)) as bill_no from sales WHERE date(updated_at)='$tgl'");

It will select the higest value in the last four characters in the bill_no. and nothing else.

So if its 0099 that is the highest it will fetch that.

So there is no need to loop over it.

Something like this

 $no = DB::select("SELECT max(right(bill_number,4)) as bill_no from sales WHERE date(updated_at)='$tgl'");
      
 $noo = (int) $no->bill_no +1;
Activity icon

Replied to Sorting Foreach By Another Variable

Not really but all of that is doable in SQL.

Activity icon

Replied to Sorting Foreach By Another Variable

Where do you get the data from?

If it's the database you should do the calculation and the sorting there.

Activity icon

Replied to Weird Css Behavior For Select Statement Laravel 8

What browser are you using?

Activity icon

Replied to Avoid Duplication

There was another type-o in the else statement it said

Sales::create($data2);

It should be

Sales::create($data);
Activity icon

Replied to Avoid Duplication

It should be $data I updated my reply.

Activity icon

Replied to Avoid Duplication

A simple solution would be to always assign the common stuff then the parts that differs with slight duplication.

Something like

  $tgl = Carbon::now()->format('Y-m-d');
      $no = DB::select("SELECT max(right(bill_number,4)) as bill_no from sales WHERE date(updated_at)='$tgl'");
      foreach ($no as $idnx) {
          $noo = (int) $idnx->bill_no;
      }

      $tambah = $noo + 1;

      if ($tambah < 10) {
          $bill_number = "E" . Carbon::now()->format('dmy') . "000" . $tambah;
      } else if ($tambah < 100) {
          $bill_number = "E" . Carbon::now()->format('dmy') . "00" . $tambah;
      } else if ($tambah < 1000) {
          $bill_number = "E" . Carbon::now()->format('dmy') . "0" . $tambah;
      } else if ($tambah < 10000) {
          $bill_number = "E" . Carbon::now()->format('dmy') . $tambah;
      }

      $data =[

          'bill_number'       =>     $bill_number,
          'user_id'     =>    Auth::user()->id,
          'tag_id'      =>    Auth::user()->team_id,
          'unit_issue_id'     =>    $request->unit_id,
          'customer_agent'      =>    $request->customer_agent,
          'payment_method'      =>    $request->payment_method,
          'borderName'      =>    $request->borderName,
          'tag_area'      =>    $request->tag_area,
          'cargo_type'      =>    $request->cargo_type,
          'chasisNo'      =>    $request->chasisNo,
          'ITNo'      =>    $request->ITNo,
          'driverName'      =>    $request->driverName,
          'License'     =>    $request->License,
          'driverPhone'     =>    $request->driverPhone,
          'subT1'     =>    $request->subT1,
          'TruckNo'     =>    $request->TruckNo,
          'TrailerNo'     =>    $request->trailerNo,
          'container_no'      =>    $request->containerNo,
          'comments'      =>    $request->comment,
          'amount'      =>    $request->amount,
          'discount'      =>    $request->discount,
          'sale_type'     =>    $request->sale_type,
          'currency'      =>    $request->currency,
          'created_at'=>$date,
        ];


      if($request->filled('backdate')) {
                    $date = request('backdate');
                } else {
                    $date = Carbon::now()->format('Y-m-d H:i:s');
                }
    if ($request->slave_ID) {
      foreach ($request->slave_ID as $key => $value) {
        $data['slave_id'] =$request->slave_ID[$key],
        Sales::create($data); 
      }

    }else{
      $data['slave_id'] = ($request->has('slave_ID') && count($request->slave_ID) > 0)? count($request->slave_ID) : null;
      Sales::create($data); 
    }
return $this->print_sales_bill_cash($bill_number);
Activity icon

Replied to It Seems That It Is Not Possible To Respond/tag Someone With A Space In Their Name.

This was the case as well with a thread where the OP was named "David Something" (not really something but anyways) and when trying to tag the OP the tagged became another user that had the name "David".

I think it's more or less impossible to handle this in the @ functionality and I think it's better to not allow spaces in the names.

Jan
20
1 day ago
Activity icon

Replied to How To Store Data From TWO Models, From Same Form (Inserting & Updating Related Models)

In this store method I update four tables

  $bookData = $request->validated();
  $book = Book::create($bookData);
  $book->addAuthors($request, $book);
  $book->addToCollection($book);
  $book->markAsRead($request, $book);

The book is the one I validate then I send the book and the request onto the add authors method and so on. I've placed these additional methods in the Book model. You can of course place them on their own model but I wanted to KISS.

public function addAuthors(BookFormRequest $request): void
    {
        if (isset($request->additional_authors)) {
            $authors = array_merge([$request->author_id], $request->additional_authors);
        } else {
            $authors = [$request->author_id];
        }
        foreach ($authors as $author) {
            AuthorBook::create([
                'author_id' => $author,
                'book_id' => $this->id
            ]);
        }
    }
Activity icon

Replied to Question About App.php Implementation Details

What do you mean by deploy app.php?

Are we talking a laravel project, a single app.php file or something totally different?

Activity icon

Awarded Best Reply on Laravel Storage Folder & Log File Permission

Check this guide, it says Ubuntu but ubuntu is based on debian.

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

Activity icon

Replied to 100k Rows With() Eager Loading Result In - Too Many SQL Parameters?

Open a new thread and ask your question. Supply information about your tables and the code used to fetch the data. Then we should be able to help you.

Activity icon

Awarded Best Reply on How To Make Docker Image

I suggest you check out this course when it comes to laravel and docker.

https://laraveldocker.com/

Jan
19
2 days ago
Activity icon

Replied to See What Validation Rules Are Failing In A Test?

Create stores it in the database you should use make instead.

I recommend using a dataprovider it makes it must cleaner

   /**
     * @test
     * @dataProvider storeValidationProvider
     * @param $fieldValue
     * @param $field
     */
    public function store_validation_tests($field, $fieldValue)
    {
        $book = Book::factory()->make([
            $field => $fieldValue
        ]);

        $response = $this->post('/books', $book->toArray());
        $response->assertStatus(302);
        $response->assertSessionHasErrorsIn($field);
    }

    public function storeValidationProvider()
    {
        return [
            'the title is required' => ['title', ''],
            'part must be numeric' => ['part', 'One'],
            'format_id is required' => ['format_id', ''],
            'format_id must exist in formats' => ['format_id', 100],
            'genre_id is required' => ['genre_id', ''],
            'genre_id must exist in genres' => ['genre_id', 100],
            'isbn is required' => ['isbn', ''],
            'invalid isbn10 cant be stored' => ['isbn', '123456789'],
            'invalid isbn13 cant be stored' => ['isbn', '9771234567890'],
            'released is required' => ['released', ''],
            'pages is required' => ['pages', ''],
            'pages must be numeric' => ['pages', 'Ten'],
            'blurb is required' => ['blurb', ''],
        ];
    }
Activity icon

Replied to Disable Secondary Route

I would go with

/shoes  (index)
/shoes/black-slippers (show)
Activity icon

Awarded Best Reply on Restricting A Specific User From Using Application

You can use a middleware to protect your routes or you can use a gate

https://laravel.com/docs/8.x/middleware

https://laravel.com/docs/8.x/authorization

Activity icon

Awarded Best Reply on Unit Testing And Axios - How?

You could assert that you location is your dashboard.

I would use Dusk or Cypress to test it though.

https://laravel.com/docs/8.x/dusk

https://www.cypress.io/

Activity icon

Replied to Two User Tables?

I would most likely move the staff specific data to it's own table and then you can easily check if the user id exists in the staffs table.

Activity icon

Replied to Two User Tables?

You should ony have one user table and then you set the type of user or a user role.

Activity icon

Replied to Restricting A Specific User From Using Application

Couldn't have said it better myself :)

Activity icon

Replied to Set Unvailable Dates

So let me get this straight. You want to mark the input red if the user inputs a value that is not a date like 2020-01-35?

Activity icon

Replied to Restricting A Specific User From Using Application

I would store a timestamp instead of a boolean.

Activity icon

Replied to WhereIn Clause To Check A Model Contains All Array Elements

It's always easier if you show us your migrations, your data and the expected result.

Activity icon

Replied to Input Multiple Tags

I would go with a regular <input type="text" name="tags"> and have the user seperate them with a ,.

Then I would explode and trim them into an array in the store method.

Activity icon

Replied to Unit Testing And Axios - How?

If you solved the issue please mark the answer that helped you as best.

Activity icon

Replied to Performance Anxiety: 1 Big Table Or 2 Smaller Tables?

As a rule of thumb, Never pull more out of the database than you need.

So if you have one table containing lots of columns then you shouldn't just do

Model::where('field', $value)->get();

You should tell it which columns to fetch for you

Model::where('field', $value)->get(['field1', 'field3', 'field6');

However you also need to consider that if one of the fields are a clob or a blob then you probably benefit by moving it to another table.

I like to think of groups when it comes to how I divide my tables.

Let's say that you have a users table that is used for authentiction and stores the users profile. then it might be a good idea to create a profiles table to store the profile specific information.

It all depends like mentioned before, how static is the table, what kind of data is stored, how many records the database contains and how many users.

In your case I probably stick with one table for the activity and then check for repetition of data in the table.

If you notice something like this it's probably a good idea to extract the activity

title   | location_id
Horseback riding | 1
Horseback riding | 2

And make it

activity_id   | location_id
1 | 1
1 | 2
Activity icon

Replied to How To Use Alias For WhereIn In Laravel

With a union I would still use id but add a virual column of type or origin so I know which table it comes from.

SELECT id, title, 'books' as origin
FROM books
UNION ALL 
SELECT id, title, 'movies' as origin
FROM movies
Activity icon

Replied to How To Use Alias For WhereIn In Laravel

Your code makes no sense at all. What is it you are trying to do?

If I have to guess this is what you are looking for

$users = User::whereIn('id', [1, 2, 3])->get();

Or

$users = User::where('id', <= 3)->get();
Activity icon

Replied to Securely Unsetting Variables After Form Redirect

Are you talking about unsetting the data in the after the return in your controller?

That is not possible to do since you returned.

You might be able to force a gc to run directly in your view by calling gc_collect_cycles(). Don't know though if it cleans a bit too much.

On the other hand your security team doesn't seem to know their drill so to speak. Regular gc is quite enough to handle this safetly.

Activity icon

Awarded Best Reply on How To Use Filter For A Collection In Laravel

If you have a collection of arrays/collections you can do something like this

$filtered = $books->filter(function($value, $key) {
	if($value['title'] == 'The Great Hunt') {
		return $value;
    }
});

That will give you all the books with the title of The Great Hunt.

I take it you are getting the data you want to filter from the database? Then you should let the database do the filtering since it's way faster and uses way less resources.

Jan
18
3 days ago
Activity icon

Replied to How To Use Filter For A Collection In Laravel

If you have a collection of arrays/collections you can do something like this

$filtered = $books->filter(function($value, $key) {
	if($value['title'] == 'The Great Hunt') {
		return $value;
    }
});

That will give you all the books with the title of The Great Hunt.

I take it you are getting the data you want to filter from the database? Then you should let the database do the filtering since it's way faster and uses way less resources.

Activity icon

Replied to How To Use Filter For A Collection In Laravel

You need to assign the filtered values to something.

$filtered = $collection->filter(function ($value, $key) {
    return $value > 2;
});

https://laravel.com/docs/8.x/collections#method-filter

Activity icon

Awarded Best Reply on How To Hide Sensitive Data From User In Front-end ?

You can use the Auth::id() in your controller or the $request->user()->idto get the logged int user id.

Then you can determine if the user can update or not.

Activity icon

Replied to How To Hide Sensitive Data From User In Front-end ?

You can use the Auth::id() in your controller or the $request->user()->idto get the logged int user id.

Then you can determine if the user can update or not.

Activity icon

Replied to Relationship With Where Clause Not Working

Either you don't pull both from the database by adding the fields you want in a pluck or get or you give it an alias.

I would go with the first option

Location_assignment::where('customer_id', $id)->join('tenants', 'location_assignment.tenant_id', '=', 'tenants.id')->where('position','=','Doctor')->get(['<table.field>','<table.field>' ]);

With the additional fields.

This is an example:

Book::get(['books.title', 'books.pages']);

The result

[!] Aliasing 'Book' to 'App\Models\Book' for this Tinker session.
=> Illuminate\Database\Eloquent\Collection {#2080
     all: [
       App\Models\Book {#2081
         title: "The Eye Of The World",
         pages: 814,
       },
       App\Models\Book {#2082
         title: "The Great Hunt",
         pages: 70,
       },
       App\Models\Book {#2083
         title: "A Memory Of Light",
         pages: 700,
       },
       App\Models\Book {#2084
         title: "Pawn Of Prophecy",
         pages: 304,
       },
     ],
   }
Activity icon

Replied to Unit Testing And Axios - How?

You could assert that you location is your dashboard.

I would use Dusk or Cypress to test it though.

https://laravel.com/docs/8.x/dusk

https://www.cypress.io/

Activity icon

Replied to Order By : Works On Local But It's Case Sensitive On The Server !

Where do you order it?

In the query to the database or somewhere else?

What OS are you running on your local machine?

Activity icon

Replied to VUE Is Regret.

Sure, here's one

https://laracasts.com

Activity icon

Replied to VUE Is Regret.

You can use whatever you like on your frontend, nobody forces you to use anything.

Vue is very good but it takes some time to learn it. The same goes for any other Javascript framework.

Don't bash the developer of something just because you don't have the knowledge yet how to use it. I really dislike jQuery but I would never state that some developer is better than the people developing it are. jQuery served it's purpose well in the past since it made stuff easier when dealing with inconsistant browsers.

The thing about newer JavaScript frameworks is that they require some new ways of working rather than just pulling in a javascript file from a CDN.

I believe this course is free and I suggest you watch it and Vue might no longer be the pain in the ass you describe.

https://laracasts.com/series/learn-vue-2-step-by-step

Activity icon

Awarded Best Reply on Laravel Form

You need a label for each checkbox.

https://www.w3schools.com/tags/tryit.asp?filename=tryhtml5_input_type_checkbox

@foreach($permission as $value)
    <label class="checkbox-inline">{{ $value->name }}
    <input type="checkbox" name="permission[]" class="form-control name" value="{{$value->id}}" 
   @if($role->permissions->contains($value->id)) 'checked' @endif>
</label>                                    
@endforeach
Activity icon

Replied to Laravel Form

You need a label for each checkbox.

https://www.w3schools.com/tags/tryit.asp?filename=tryhtml5_input_type_checkbox

@foreach($permission as $value)
    <label class="checkbox-inline">{{ $value->name }}
    <input type="checkbox" name="permission[]" class="form-control name" value="{{$value->id}}" 
   @if($role->permissions->contains($value->id)) 'checked' @endif>
</label>                                    
@endforeach
Activity icon

Replied to Fetch Only Id From Array

Something like this should work.

$ids = [];

foreach($values as value) {
 $ids[] = value['id'];
}

However if you are fetching from the database to something like this

$ids = Model::get('id');