Tray2

Tray2

Member Since 4 Years Ago

Solna

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

Experience Points 171,100
Experience Level 35

3,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 1133
Lessons
Completed
Best Reply Awards 101
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.

21 Jul
1 day ago

Tray2 left a reply on Undefined Variable

When you test are you hitting the / or /pods

/returns the view without hitting the index method in you controller just like @snapey says. You need to hit the/pods which uses the controller method

Tray2 left a reply on How To Reauired

It's a typ-o it should be $request

Tray2 left a reply on Decrement And Increment The Stock Daily

I would do something like this.

A shipment is received with ten pallets of some part. This information is stored in a transactions table like so

id        | part                  | qty                    | date              |trans_type
----------------------------------------------------------------------------------------------
1         | 1235                 |             1000     | 2019-07-21 | arrival

Then I'd have a parts/products table where I have the amount on the pallet and some other part specific information.

id        | part                  | pallet_qty        | description |weigth (g)
----------------------------------------------------------------------------------------------
1         | 1235                 |             100      | cartridge      | 150

Upon arrival the 1000 pieces are split with the pallet qty and for each a material unit is created in a material_units table

id        | part                  | qty                    | shipment_id |address    | active
--------------------------------------------------------------------------------------------------------
1         | 1235                 |             100       |                   1   | 12564      |     Y
--------------------------------------------------------------------------------------------------------
2         | 1235                 |             100       |                   1   | 12565      |     Y
--------------------------------------------------------------------------------------------------------
3         | 1235                 |             100       |                   1   | 12566      |     Y
--------------------------------------------------------------------------------------------------------
4         | 1235                 |             100       |                   1   | 12567      |     Y
--------------------------------------------------------------------------------------------------------
5         | 1235                 |             100       |                   1   | 12568      |     Y
--------------------------------------------------------------------------------------------------------
6         | 1235                 |             100       |                   1   | 12569      |      Y
--------------------------------------------------------------------------------------------------------
7         | 1235                 |             100       |                   1   | 12570      |      Y
--------------------------------------------------------------------------------------------------------
8         | 1235                 |             100       |                   1   | 12571      |      Y
--------------------------------------------------------------------------------------------------------
9         | 1235                 |             100       |                   1   | 12572      |      Y
--------------------------------------------------------------------------------------------------------
10       | 1235                 |             100       |                   1   | 12573      |      Y

The shipment id is to connect it to which shipment it belongs to and the address is where in your storage it's placed.

Now your stock of a part is just to sum the qty in the material_unit table for each part.

So when you do a decrease of the stock (shipping goods out) you do the following.

Add a record to the transactions table

id        | part                  | qty                    | date              |trans_type 
----------------------------------------------------------------------------------------------
1         | 1235                 |             1000     | 2019-07-21 | arrival
----------------------------------------------------------------------------------------------
2         | 1235                 |                     1    | 2019-07-22 | depart

In an orders table you connect the order to the material_unit id and decrease the qty by the ordered amount. When the mu is empty you change the active to 'N'.

id        | part                  | qty                    | shipment_id |address    | active
--------------------------------------------------------------------------------------------------------
1         | 1235                 |                 0       |                   1   | 12564      |     N
--------------------------------------------------------------------------------------------------------
2         | 1235                 |              99        |                   1   | 12565      |     Y
--------------------------------------------------------------------------------------------------------

That way you will alway have up to date stock.

Tray2 left a reply on How To Reauired

You can use the requiredIf validation rule.

Something like

$request_>validate(['referal_code' => Rule::requiredIf(function () use ($request) {
        return $request->familiar == 4;
    })]);
20 Jul
2 days ago

Tray2 left a reply on Undefined Variable

To start with you have commented out the assignment of the `$pods´ variable .

Then you send back an array with the key testthat ha been assigned the empty variable ´$pods´.

Then in you view you are trying to loop over ´$pods` which should be$test` since it's the key in the array.

public function index() 
{ 
    // $pods = Pod::all();
  return view('pods.index', ['test' => $pods]); 
}

Tray2 left a reply on Make The First Button Click, And Click The Second Button But It's On 1 Button

There is only one button that sends a post to a url where the code above checks a wheter you are logged in or not then executes the proper code.

<form action="/somemodel" method="POST">
    <input type="submit">
</form> 
Route::post('/somemodel', [email protected]');
public function toggleCheck()
{
    $user = Auth::user();

    if ($user->isCheckedIn() {
            $user->checkout();
            return 'Checked out';
    }

    $user->checkIn();
    return 'Checked in';
}

Tray2 left a reply on How To Validate Multiple Different Fields Using Only One Request?

Sounds like you want to check that all fields are filled in.

$request->validate([
    'name' => 'required',
    'age' => 'required',
    'place' => 'required'
]);

But I might be wrong in what it is you want to calidate.

19 Jul
3 days ago

Tray2 left a reply on Random Generate Number For Customer Id

Have you done a php artisan migrate:fresh?

Be careful it will delete all you data.

If that is out of the question you can create a seperate migration for just adding the alter table statement

Tray2 left a reply on Random Generate Number For Customer Id

Add this to your migration

DB::statement("ALTER TABLE customer_id AUTO_INCREMENT = 10000;");

Then it will start at 10000.

This is in my opinion bad since you are limiting yourself even more on how many customers you can have.

Tray2 left a reply on Encrypting Model Data

When I want to change the data before insert I add and setAttribute method to my model

public function setTitleAttribute($value)
    {
        $this->attributes['title'] = ucwords(strtolower($value));
    }

This one enforcing that all words in the title starts with an uppercase.

So something like

public function setTitleAttribute($value)
{
    $this->attributes['title'] = encrypt($value));
}

public function getTitleAttribute($value)
{
    return decrypt($value);
}

Should do the trick.

Tray2 left a reply on Random Generate Number For Customer Id

Why not use a regular sequence number for example the tables id column.

With only five digits you ar limiting the application to 99999 customers.

Eight should be enough but ten is a nice even number.

Tray2 started a new conversation Data Found With Manual Browser Test But Not With Phpunit

I'm building a Media Register where among other thing you can store your books and I ran into an intresting issue.

From the author show view I have a link to the create route. On said route I add the sluggified complete authors name so the url looks like this.

/books/create?author=jordan_robert

So I wrote a test for this looking like so

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

        $response = $this->get('/books/create?author=' . str_slug('jordan-robert'));

        $response->assertSee('value="Jordan, Robert"');
        $response->assertSee('value="1"');
    }

And my create method looks looked like this

   public function create(Request $request)
    {
        $author = '';
        if($request->has('author')) {
            $authorName = explode('-', $request->query('author'));
            $author = Author::where('first_name', $authorName[1])->where('last_name',  $authorName[0])->get();
        }
        $genres = Genre::orderBy('genre')->get();
        $formats = Format::orderBy('format')->get();
        return view('books.create', compact('genres', 'formats', 'author'));
    }

Now this test fails since it does not find the author even though it's created. However when I do this in the browser it works perfectly.

After almost an hour I found the issue. There is a difference in how the code is executed.

When running in the browser the query is case insensitive while when ran from phpunit it's case sensitive.

So I had to add ucFirst to the query like so.

   public function create(Request $request)
    {
        $author = '';
        if($request->has('author')) {
            $authorName = explode('-', $request->query('author'));
            $author = Author::where('first_name', ucFirst($authorName[1]))->where('last_name', ucFirst($authorName[0]))->get();
        }
        $genres = Genre::orderBy('genre')->get();
        $formats = Format::orderBy('format')->get();
        return view('books.create', compact('genres', 'formats', 'author'));
    }

And then it works in both browser and phpunit.

Tray2 left a reply on Get Data For Dashboard

Depends on your database model but 1 and 2.

Let's say you want all the posts waithing for approval and The popular tags that would both use method 1.

If you want The five newest members and a smal sample of their three latest posts it would use 1 for the members and 2 for the posts.

So if they are related use the relationship if not pass it from the controller.

Tray2 left a reply on User Profile Table Does It Good Or Bad Idea ?

That depends, if it's just a few fields go for it but if it's lots then I'd rather create one or more tables just to keep the amount of fields low. It's more a question of taste than anything else.

Tray2 left a reply on Laravel Redirect Does Not Work At All

Remove this

{!!Form::autoForm(\App\Models\Main\Product::class,"main/system/products/update")!!}

And replace it with proper form code.

Tray2 left a reply on Validation Errors Not Showing

That you need to add code for.

For example

<input type="text" name="username" value="{{ old('username') }}">
@if($errors->has('username')
    <div class="error">This field is required</div>
@endif

Tray2 left a reply on Make The First Button Click, And Click The Second Button But It's On 1 Button

Not knowing your other code but something like

$user = Auth::user();

if ($user->isCheckedIn() {
    $user->checkout();
    return 'Checked out';
}

$user->checkIn();

Tray2 left a reply on Laravel Redirect Does Not Work At All

This looks strange

\request('id')

Shouldn't it be

$request('id')

or

$request->id

Is your request passing your validation?

Tray2 left a reply on Validation Errors Not Showing

What does your store method look like?

Tray2 left a reply on Changing Migration Tables

I suggest you use the Laravel naming convention for your tables

part should be parts and f_part should be f_parts

That will save you some time not having to add the table name to your models.

https://laravel.com/docs/5.8/eloquent#eloquent-model-conventions

Tray2 left a reply on How To Get Value From JSON Array Using Element By Id In Javascript?

To get the first name you do

obj.employees[0].firstname;

Tray2 left a reply on Setting A Value For An Input

Like @raravel say you need yo add quotes to the value when you call the function.

myFunction(123);

Will work since it's a number however

myFunction(ABC123);

will not work since ABC123 isn't a number and it isn't a string either.

myFunction('ABC123');

Will work since it is a string.

18 Jul
4 days ago

Tray2 left a reply on If Condition Is Not Working

There are so many inconsistancies in your code so I don't even know where to begin.

  1. You have two columns in you migration file with the name title
 $table->text('title');
 $table->LONGTEXT('title');

Remove the second one.

  1. You have all capitals in your migration
$table->LONGTEXT('slug');

PHP is case sensitive so change to

$table->longText('slug');

  1. In your view you have missed quoting property values in several places among other
<input type="text" name=link class="form-control" placeholder="" id="mdate">

Change to

<input type="text" name="link" class="form-control" placeholder="" id="mdate">

So now if you want to validate the fields in your store method you need to do something like this

$request->validate([
    'title' => 'required',
    'date_time' => 'required|date'
    'category_id' => 'required|exits:categories',
    
]);

You will need to validate the other fields too except slug since you probably generates that from the title. Those fields should not have required rule.

The file you can use the 'mimes`validation for images it could look like this

'mimes:jpeg,bmp,png'

This is stuff you will learn by watching the free videos on this site.

All the conditions after you validation looks like gibberish to me and I have no clue of what you are trying to do.

Remove them and start over is my suggestion. Get a bare minimum to pass the validation and store it in the database.

Something like

public function store(Request $request)
{
    $request->validate([
        'title' => 'required',
        'date_time' => 'required|date'
        'category_id' => 'required|exits:categories',
    ]);

    $post = new Post();
    
    $post->title = $request->title;
    $post->date_time = $request->date_time;
    $post->category_id = $request->category_id;
    $post->slug = Str::slug($request->title);

    $post->save();
    
    return redirect('/posts')->with('status', 'Post saved!');
}

Then add field for field until you have everything in place.

Tray2 left a reply on How To Add Confirmation Details Page Before Form Submitting?

I would probably use a modal for that.

Something like.

<styles>
    .hidden-submit {
        margin-left: -9000px;
    }

    .hidden {
        display: none;
    }
</styles>


<form action="/somemodel" method="POST">
    <submit id="submit-button" class="hidden-submit>
    <button onclick="openConfirmationModal()>Preview</button>
</form>


<div id="confirmationModel" class="hidden">
    Display you data


    <button onclick="submitForm()">Save</button>
</div>


<script>

    function openConfirmationModal() {
        document.querySelector('#confirmationModal').classList.remove('hidden');
    }

    function submitForm() {
        document.querySelector('#submit-button').click();
    }
</script>

Tray2 left a reply on Use Html, Sanitize It And Show It In View

htmlentities converts everything including the tags to &lt;body&gt; so that is why it don't render for you.

Have you set the proper meta tag in your header and have you the correct character setup in your database?

Tray2 left a reply on Multi User Type In One Table , One Dashboard But Want To Show Menu User Type Login Wise How To Do That ?

In you controller you can do something like

if( Auth::user()->type == 'Admin') {
    return view('admin.dashboard');
} else if (Auth::user->type == 'user' {
    return view('user.dashboard');
} else {
    return view('assistant.dashboard');
}

Or you can handle it in your views

@if(Auth::user()->type == 'Admin')
    Show admin stuff
@endif
@if(Auth::user()->type == 'User')
    Show user stuff
@endIf

Tray2 left a reply on I Have A 404 Error In My Web Server

404 usually means that the browser is trying to access a route that does not exist.

It could also mean that the browser is trying to access a record that does not exist in the database.

Since you say that it has been working before it could be that the database is not functioning properly or that the mod_rewrite has been turned off in apache.

Tray2 left a reply on Composer Update Issues, Have Not Run Across This So I Don't Know What To Do

I strongly recommend not using laravelcollective/html since it make your code harder to read and debug.

Tray2 left a reply on Trying To Get Property Laravel

What does the table look like?

17 Jul
5 days ago

Tray2 left a reply on Want To Create User Table But I Don't Understand What Can I Do Create Customize User Table Or Use Laravel Built In Auth

You should take a look at migrations here https://laravel.com/docs/5.8/migrations

There you will see how to create and change table layouts.

Tray2 left a reply on Feeback Towards The Courses?

What I did when I started learning Laravel was to watch all the tutorials once without doing any code and then watch them again and code along.

You should always code along at least once.

The from scratch videos covers most basics so a couple of times through them and then on to one of the larger courses where you get to see most of the stuff in a real application.

https://laracasts.com/series/build-a-laravel-app-with-tdd

https://laracasts.com/series/lets-build-a-forum-with-laravel

As a compliment to Laracasts I suggest you buy Matt Stauffers Laravel Up and Running 2nd edition.

It's impossible to remeber everything even for a profesional developer. I work with Oracle PL/SQL every day isince 2015 and I google stuff ;)

Tray2 left a reply on Safari Specific Date Input Bug

You could always do the lazy thing and create three dropdowns year, month, day.

Tray2 left a reply on Safari Specific Date Input Bug

@cronix now why didn't I think of that ;)

Tray2 left a reply on Safari Specific Date Input Bug

I think you are stuck doing it in Carbon like you are doing. There might be some method in Carbon that can make it easier for you but I couldn't find any at first glance.

You could maybe do some reqular expressions to check the format

Something like

^(19|20)\d\d[- /.](0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])$ 

Should cover most 'yyyy-mm-dd' and yyy/mm/dd

^(0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.](19|20)\d\d$.

Should cover dd-mm-yyy and dd/mm/yyyy

Tray2 left a reply on Safari Specific Date Input Bug

I always check here for what browsers support what.

https://caniuse.com/#search=input%20type%20date

<input type="date" placeholder="yyy-mm-dd">

Can help you a bit and inform the user about the correct format.

Tray2 left a reply on Best Way To Test An Eloquent Model Method Which Calls A Static Method On The Same Class?

@jeffreyway , that has been going on for a while now, maybe threads older than three months or somesuch should be locked from adding replies to.

Tray2 left a reply on Error SQLSTATE[22007]: Invalid Datetime Format: 1366 Incorrect String Value: '\xC5\x8D-tan...' In Laravel

You are trying to save something that is not a date into your datetime column.

Show us the code of the method that gives the error.

Tray2 left a reply on Pivot Table For 3 Models?

Getting a good database model can be tricky but try to keep it as simple as possible is the best way to go.

Check the docs for Plymorphic Relationships for more info-

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

Tray2 left a reply on Javascript D-block Not Working.

I do this for free in my spare time to help others and not to write complete solutions for others.

If you still can't grasp how javascript works I suggest you take the free course provided by Wes Bos

https://javascript30.com/

Tray2 left a reply on Javascript D-block Not Working.

Something like that yes.

Just use .classList.add('d-none'); to add the class again.

Tray2 left a reply on Pivot Table For 3 Models?

If they are so "different" you can always add another table with something like

product_properties

  • id
  • product_id
  • property
  • value

So then you can have as many different propeties as you like

1 1 horsepower 800 2 1 cylinders 8 3 2 diameter 4 4 2 thickness 2.5

and so one still using a one to many relation.

Tray2 left a reply on Datatables Can Showing Data/result But Sometimes Often Get Error 404

Without any code it's very hard dogive you an answer since we don't know what you are trying to do.

However if you have something like

public function show($id)
{
    return Model::findOrFail($id);
}

in your controller and you call try to find an id that does not exist you will get a 404 response.

https://mysite.com/api/books/1 this gives a 200 response if you have the id in the database

https://mysite.com/api/bokos/1000 this gives you a 404 if you don't have the id 1000 in you table.

Tray2 left a reply on Javascript D-block Not Working.

So if someone clicks one of your radiobuttons you want to display something?

You can do this

<input class="form-check-input" type="radio" name="familiar" id="marketer" value="4" onclick="showReferal()">

and this

<script>
     function showReferal() {
         document.querySelector('#referral_code').classList.remove('d-none');
     }
</script>

Even so I think you need to think about what you are doing.

A radio button can't be unchecked by clicking it again.

Are you planning on showing other stuff when the others are clicked? If so don't forget to hide the other ones in your code.

Tray2 left a reply on Pivot Table For 3 Models?

I would not do it that way I would use one to many relations instead..

I would do a supplier table, a products table and a product types table.

The suppliers table

  • id
  • name

The product_types table

  • id
  • type

The products table

  • id
  • name
  • description
  • price
  • supplier_id
  • product_type_id

Tray2 left a reply on BelongsToMany Trying To Get Property 'id' Of Non-object Error

That gives you an array and you can't $country->id on it so either you make a collection in your controller or you do {{ $country['id'] }}

Tray2 left a reply on BelongsToMany Trying To Get Property 'id' Of Non-object Error

When using php in the view like I suggested you need to wrap it in curly braces

{{ dd($country }}

Otherwise it will only output the text dd($country) instead of the content in the variable.