woxene

woxene

Member Since 3 Months Ago

Experience Points 990
Experience
Level
Lessons Completed 0
Lessons
Completed
Best Reply Awards 0
Best Answer
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.

15 Sep
1 month ago

woxene started a new conversation Displaying An Image From The Local Disk.

I have an image upload that uploads to the local disk :

//This one;
'disks' => [
    'local' => [
        'driver' => 'local',
        'root' => storage_path('app'),
    ],
],

And the file gets stored in the current location:

(rootfolder)\storage\app\carrier_logo\ ycWmHb2RtjYNIcj1w5CzzNLw1gA5rtz7u552Js2A.png

//Filetree of this location:
+---app
|   |   .gitignore
|   |
|   +---carrier_logo
|   |       ycWmHb2RtjYNIcj1w5CzzNLw1gA5rtz7u552Js2A.png //This is the file i want to show.
|   |
|   \---public
|           .gitignore
|

Now I want to display this image in my template. But I can't seem to fetch the image.

woxene left a reply on Is This A Laravel Bug? Getting Filepath After Upload

@Cronix Even with this code, it saves the temp path for the file. This is the updated function I used.

 public function store(Request $request)
 {
     request()->validate([
         'name'              => 'required',
         'logo'              => 'nullable',
         'original_filename' => 'nullable',
     ]);
     
     $data = $request->all();
     
     if ($request->hasFile('logo')) {
         $data['original_filename'] = $request->file('logo')->getClientOriginalName();
         $data['path'] = $request->file('logo')->store('carrier_logo');
     }
     
     Carrier::create($data);
     return redirect()->route('carriers.index')->with('toast', 'Carrier created successfully.');
 }

This is the data posted to the database:

logo = C:\xampp\tmp\php7C4A.tmp(this is wrong) original_filename =image.png(this is good)

Any more ideas? I have absolutely no idea what to do here..

14 Sep
1 month ago

woxene left a reply on Is This A Laravel Bug? Getting Filepath After Upload

@Snapey Could you show me how this should be done? What is the best way to achieve this?

woxene started a new conversation Is This A Laravel Bug? Getting Filepath After Upload

I know how fileupload works and I know how to use it. But I found something strange today;

I get my path (and move the uploaded image) with this function: $path = $request->file('logo')->store('carrier_logo'); Which comes straight out of the laravel docs.

When I dump this variable using dd($path); the output is "carrier_logo/bHfFyYagJYG5nadKOVZjgxrRvncw4jsl7Of7PKEB.png"

Which is exactly what I want to write in my database. But when I merge this into the database something strange happens.. it changes into C:\xampp\tmp\php3C3A.tmpand I have no idea why or how this is happening..

Here is my full code:

    public
    function store(Request $request)
    {
        request()->validate([
            'name'              => 'required',
            'logo'              => 'nullable',
            'original_filename' => 'nullable',
        ]);
        
        if ($request->hasFile('logo')) {
            $path = $request->file('logo')->store('carrier_logo');
            dd($path); //outputs: "carrier_logo/bHfFyYagJYG5nadKOVZjgxrRvncw4jsl7Of7PKEB.png"
            $request->merge([
                'logo'              => $path, //outputs : C:\xampp\tmp\php3C3A.tmp
                'original_filename' => $request->file('logo')->getClientOriginalName(),
            ]);
        }
        
        Carrier::create($request->all());
        return redirect()->route('carriers.index')->with('toast', 'Carrier created successfully.');
    }
10 Sep
2 months ago

woxene started a new conversation Get The Location For Uploaded Files (storage Path + Hashed File Name + Extention)

I have an upload where images can be uploaded. I have 2 fields dedicated for the image(which is a logo) logo and original_filename.

Right now when I upload only the original_filename seems to work. The other one takes the temp location and places the following in the database: C:\xampp\tmp\phpF3EC.tmp Which of course is not what I want to happen. I want this to be carrier_logo/ZbCG0lnDkUiN690KEFpLrNcn2exPTB8mUdFDwAKN.png for example.

Here is my controller function:

public function store(Request $request)
{
    request()->validate([
        'name'              => 'required',
        'logo'              => 'nullable',
        'original_filename' => 'nullable',
    ]);
    
    //This is where the file uploads?
    if ($request->hasFile('logo')) {
        //Get location, doesn't work now.
        $path = $request->file('logo')->store('carrier_logo');
        //Get original name
        $original_filename = $request->file('logo')->getClientOriginalName();
        
        //Add to request
        $request->merge([
            'logo'              => $path,
            'original_filename' => $original_filename,
        ]);
    }
    
    Carrier::create($request->all());
    return redirect()->route('carriers.index')->with('toast', 'Carrier created successfully.');
}

woxene left a reply on Call To A Member Function Store() On Null When Uploading Image

Got it working, I forgot the change ('file') to ('logo').

woxene started a new conversation Call To A Member Function Store() On Null When Uploading Image

When uploading an image I get the following error: Call to a member function store() on null

Here is my controller code:

public function store(Request $request)
{
    request()->validate([
        'name' => 'required',
        'logo' => 'nullable',
        'original_filename' => 'nullable',
    ]);
    
    if ($request->hasFile('logo')) {
        $path = $request->file('file')->store('fileupload');
        $fileinfo = $request->file('file');
        
        $request->merge([
            'logo'              => $path,
            'original_filename' => $fileinfo->getClientOriginalName(),
        ]);
    }
    
    Carrier::create($request->all());
    return redirect()->route('carriers.index')->with('toast', 'Carrier created successfully.');
}

I want the script to upload the file to the folder /fileupload and add logo and original_filename to the database.

woxene left a reply on Saving Data (including A Logo) From Form Into Database.

Thank you! Works perfectly. Only thing is

// This:
'logo' => $request->file('logo')->store('files');
// should be this (my IDE gave me an error with the above.
'logo' => $request->file('logo')->store('files'),

Thanks a lot :)

09 Sep
2 months ago

woxene started a new conversation Saving Data (including A Logo) From Form Into Database.

I know how it works for normal fields(everything but images), and I have saved images before, but in their separate DB where they were linked to the user profile they were uploaded in. But never have I combined the two, which for some reason doesn't seem like a straight forward thing to do.

I will post my form, controller and model here so maybe someone can spot the error..

Controller:

public function store(Request $request)
{
    if ($request->hasFile('file')){
        $path = $request->file('file')->store('files');
        
        return $path;  
    }
    
    request()->validate([
        'name' => 'required',
        'file' => 'nullable',
    ]);
    
    Carrier::create($request->all());
    return redirect()->route('images.index')->with('toast', 'Image created successfully.');
}

form:

<form method="POST" action="{{ route('images.store') }}">
    @csrf
    <div class="row">
        <div class="input-field col s12">
            <label for="name"> Name</label>
            <input id="name" class="{{ $errors->has('name') ? ' invalid' : '' }}" type="text" value="{{ old('name') }}" name="name" required autofocus>
        </div>
    </div>
    <div class="row">
        <div class="file-field input-field col s12">
            <div class="waves-effect waves-light hoverable btn-small white-text">
                <span>Upload Image</span>
                <input type="file" name="file" id="file">
            </div>
            <div class="file-path-wrapper">
                <input class="file-path validate" type="text">
            </div>
        </div>
    </div>
    <div class="card-action right-align">
        <button class="waves-effect waves-light btn-small hoverable" type="submit">Add picture</button>
    </div>
    {{--Error handling--}}
    @if ($errors->any())
        @foreach ($errors->all() as $error)
            <script>M.toast({html: '{{ $error }}'})</script>
        @endforeach
    @endif
</form>

Model:

class Carrier extends Model
{
    /**
     * @var array
     */
    protected $fillable = [
        'name',
        'image',
    ];
}

I have tested the form already, (I used dd($request);to check) and it the request object does in fact contain the Image. I will paste the result below.

+request: ParameterBag {#64 ▼
    #parameters: array:3 [▼
      "_token" => "DJTD5hwxXutj6uaCmBiEuO9ob6Ushzi7kG6iDQdy"
      "name" => "testtt"
      "file" => "1200px_Service_logo_2014.svg.png"
    ]
  }
28 Aug
2 months ago

woxene left a reply on Adding Current Time To Request In Laravel With Carbon

@cmdobueno Thank you for taking the time to write that out. It is much appreciated that you (and @Yorki) are taking the time to help the people on this platform.

In my 'defence' I would like to clarify that with saying it was a typo I meant it was just a stupid mistake. As soon as I re-read my own code I saw my flaw and adjusted it, hoping no one saw the mistake I had made. But that was too late already. And as not being a beginner in PHP I took the comment @Yorki provided as an insult (again; Sorry).

Perhaps my English knowledge was the thing that made it a little messy here. So for everyone involved. I apology.

Back on topic: The problem has been solved and this is the code right now:

public function editAll(Request $request)
{
    //variable declaration
    $type = $request->type;
    $posted_ticket_number = $request->ticket_number;
    
    switch ($type) {
        case 'modal-start-picking':
            //validate
            $request->validate([
                'picker' => 'required',
            ]);
            
            //update
            Ticket::where('ticket_number', $posted_ticket_number)->update([
                'picker'            => $request->picker,
                'picker_start_time' => Carbon::now(),
            ]);
            break;
        
        case 'modal-finish-picking':
            //no validation for this one.
            
            //update
            Ticket::where('ticket_number', $posted_ticket_number)->update([
                'picker_finish_time' => Carbon::now(),
            ]);
            break;
    }
    
    return redirect()->route('tickets.index')->with('toast', 'Ticket updated successfully');
}

woxene left a reply on Adding Current Time To Request In Laravel With Carbon

That's quite a statement to make there @Yorki ... The fact that I misspell one character doesn't mean I 'lack basic knowledge of PHP'. But thanks anyways.

woxene left a reply on Laravel Update Without Passing ID

I figured out I had to change my controller. I now have changed it like this :

public function startpicking(Request $request)
{
    $posted_ticket_number = $request->ticket_number;
    
    $request->validate([
        'picker' => 'required',
    ]);
    
    Ticket::where('ticket_number', $posted_ticket_number)->update(array_merge($request->all(), ['picker_start_time' => Carbon::now()]));
    return redirect()->route('tickets.index')->with('toast', 'Ticket updated successfully');
}

Now I get the following error :

SQLSTATE[HY000]: General error: 1 no such column: _token (SQL: update "tickets" set "_token" = (mytoken), "type" = modal-start-picking, "ticket_number" = test, "picker" = MS, "picker_start_time" = 2018-08-28 12:42:17, "updated_at" = 2018-08-28 12:42:17 where "ticket_number" = test)

woxene left a reply on Laravel Update Without Passing ID

@Snapey I am sorry, Might be the fact that english is my 2nd language,

Let me explain again, and a little more detailed:

I have a one page design with 6 buttons. Each button has a form already loaded in. (but hidden with JavaScript). When you click the first button, the first form comes out. This is a form where the user can make a ticket. (a ticket has 25 properties(idk if this is the right word) in the first form you fill in about 8. the other 17 will be null in the database). Submitting this form adds the filled in fields (also ticket_number) will be added to the database.

Now the overview page shows the table with all records in the database. (there is no functionality here. it is only for showing.)

The 2nd button is a button to edit a ticket. in the form there are 2 fields : ticket_number and picker. The ticket number gets scanned from a QR code and simply put in the input field. And the picker is to know who is picking this ticket. Now, upon submitting I want my controller to find the right ticket (looking at ticket_numberas that is the only unique Identifier I have at the moment) and update the fields picker and picker_start_time(picker_start_time gets defined in the controller).

I just don't know how to controller part should work.

woxene left a reply on Laravel Update Without Passing ID

@Snapey , no I don't get the ticket ID because the edit forms are located on the overview page (where all Tickets are) I basically wan't all of this to be a onepage design. with as few refreshes as possible.

The way I want it to work could be explained best as skipping the public function edit(Request $request, Ticket $ticket) function (generated by default) and bringing the form directly to the update function.

Hope my explanation makes sence.

woxene started a new conversation Laravel Update Without Passing ID

I am working on a ticket log where tickets get edited multiple times before they are 'done'.

I have an overview where you see all the tickets, on top of the page are 6 buttons. All buttons open a popup with a form. The first button is a create function which makes the ticket and fills in the first information. All other fields are now NULL. The second buttons is the first edit button.

Upon opening it opens an form where the user scans a barcode to fill in the first field; Ticket Number. this ticket number is unique for every Ticket. Next thing to fill in is your credentials, which come from a dropdown.

Due to the fact that all the edit forms work by Ticket_number (which is scanned from a QR code) I made it so all forms are on the same page. Therefor I am not able to do something like : action="{{ route('countries.update',$country->id) }} as I don't know the ID at this moment.

Here is the code behind everything(and you can see what I tried there too):

web.php:

     //    TICKET LOG ROUTES
     Route::post('ticket/start-picking', '[email protected]')->name('tickets.startpicking');
     Route::resource('tickets', 'TicketController');

form for edit:

    <div id="modal-start-picking" class="modal">
        <form method="POST" id="modal-start-picking-form" action="{{ route('tickets.startpicking') }}">
            @csrf
            <input type="text" value="modal-start-picking" name="type" hidden>
            <div class="modal-content">
                <h4>Start Picking</h4>
                <p>Scan Ticket Number here</p>
                <div class="input-field">
                    <label for="start">Ticket Number</label>
                    <input type="text" name="ticket_number" id="start" autofocus>
                </div>
                <div class="input-field">
                    <select id="picker" name="picker">
                        <option value="" disabled selected>Choose a Picker</option>
                        @foreach($employees as $employee)
                            <option {{(old('picker') == $employee->initials ) ? 'selected' : ''}} value="{{ $employee->initials }}">{{ $employee->initials }}</option>
                        @endforeach
                    </select>
                </div>
            </div>
            <div class="modal-footer">
                <input class="btn-flat" type="submit" value="Start Picking">
            </div>
        </form>
    </div>

Function in TicketController:

    public function startpicking(Request $request, Ticket $ticket)
    {
        $request->validate([
            'picker' => 'required',
        ]);
        
        $ticket->update(array_merge($request->all(), ['picker_start_time' => Carbon::now()]));
        return redirect()->route('tickets.index')->with('toast', 'Ticket updated successfully');
    }

If any more info is required I Will gladly update my post.

woxene left a reply on Adding Current Time To Request In Laravel With Carbon

I am opening a new discussion for this as I found the problem. It is a little bigger then I thought and not relevant to what I wrote here.

woxene left a reply on Adding Current Time To Request In Laravel With Carbon

i var dumped the ticket and it is the right one, Also yes. it is in fillable

woxene left a reply on Adding Current Time To Request In Laravel With Carbon

My update function updates a record in the database which has fields as NULL.

woxene left a reply on Adding Current Time To Request In Laravel With Carbon

Neither of these solutions seem to work. I don't get an error but nothing get's added to the database.

woxene left a reply on Adding Current Time To Request In Laravel With Carbon

It is supposed to fill the picker_start_time with the current time, the error I get now :

the picker_start_time field is required.

I want to assign the time in the controller and not in the browser.

woxene started a new conversation Adding Current Time To Request In Laravel With Carbon

I want to add the current time to the database (This needs to happen on the server + it has to happen multiple times (start, finish etc). This is the code I came up with but this doesn't work.

        public function startpicking(Request $request, Ticket $ticket)
        {
            $request->input('picker_start_time') == Carbon::now();
            
            request()->validate([
                'picker'            => 'required',
                'picker_start_time' => 'required',
            ]);
            
            $ticket->update($request->all());
            return redirect()->route('tickets.index')->with('toast', 'Ticket updated successfully');
        }

Can someone help me?

24 Aug
2 months ago

woxene left a reply on Returning A Custom Variable Upon Validator Fail.

Works! Wow, how could I look over this.. Was thinking way to much for this one.

woxene started a new conversation Returning A Custom Variable Upon Validator Fail.

I have a page with 5 forms and When one of them fails the validator I want my controller to send a variable (from a hidden field in my form) back to the page. I need the variable of the form that submitted.

I have this line in all of my forms (with their own unique value) <input type="text" value="modal-entry" name="type" hidden>

And then I have the following script I want to run through:

<script>
    @if (count($errors) > 0)
        const reopenModal = '{{ $variable_from_my_form_has_to_go_here }}';
        switch (reopenModal) {
            case 'thing1':
                $('#modal-entry').modal('open');
                break;
            case 'thing2':
                $('#modal-edit').modal('open');
                break;
            default:
        }
    @endif
</script>

My script basically opens up the modal that closed when there are errors. To do so I need to know which Modal closed. (each modal has a form)

23 Aug
2 months ago

woxene left a reply on Laravel Form Submit And MaterializeCSS Modals.

@Cronix That sounds great. Unfortunately the last option you gave me does not work for me.

Are you able to assist me on using AJAX to submit the form? I have never done that before.

woxene started a new conversation Laravel Form Submit And MaterializeCSS Modals.

I have a form inside a Modal, Everything works fine (everything: The form sends, the form validates, the form fields can go in the database.)

There's just one thing that doesn't seem to work.

Upon submitting the form, the Modal closes. Problem here is that when the Validator finds any problems you need to reopen the Modal to edit the fields so it can go through the Validator.

The solution I am looking for? : Either making the Modal not close when the Validator finds any errors. Or Reopening the Modal when the Validator finds any errors.

What would be my best option here?

Here is my code:

<div id="modal-finish" class="modal">
    <div class="modal-content">
        <form method="POST" action="{{ route('tickets.store') }}">
            @csrf
            <span class="card-title">Start a new Ticket/span>
            <div class="row">
                <div class="input-field col s12">
                    <label for="comment">Comment</label>
                    <input id="comment" class="{{ $errors->has('comment') ? ' invalid' : '' }}" type="text" value="{{ old('comment') }}" name="comment">
                </div>
            </div>
            <div class="row">
                <div class="input-field col s12">
                    <label for="ticket_number">Ticket Number</label>
                    <input id="ticket_number" class="{{ $errors->has('ticket_number') ? ' invalid' : '' }}" type="text" value="{{ old('ticket_number') }}" name="ticket_number">
                </div>
            </div>
            {{--Error handling--}}
            @if ($errors->any())
                @foreach ($errors->all() as $error)
                    <script>M.toast({html: '{{ $error }}'})</script>
                @endforeach
            @endif
        </form>
    </div>
    <div class="modal-footer">
    </div>
</div>

woxene started a new conversation How To Check If I Found A Result Or Not?

My script doesn't seem to be able to detect an empty result.

This is my function.

public function find(Request $request)
{
    $ticket = Ticket::where('ticket_number', $request->ticket_number)->firstOrFail();
    if (!empty($ticket)) {
        $type = $request->input('type');
        switch ($type) {
            case 'start':
                return view('tickets.forms.start', compact($ticket));
                break;
            case 'finish':
                return view('tickets.forms.finish', compact($ticket));
                break;
            case 'shipping';
                return view('tickets.forms.shipping', compact($ticket));
                break;
            case 'check';
                return view('tickets.forms.check', compact($ticket));
                break;
            default:
                return redirect()->route('tickets.index')->with('success', 'Something went wrong.');
        }
    } else {
        return redirect()->route('tickets.index')->with('success', 'This Ticket Number does not match our records.');
    }
}

When there's no result found in $ticket it just redirects to a 404. I would like to change this behavior so it executes the else statement. How is this done?

woxene started a new conversation 4 Edit Functions From One Page.

I have quite a hard challenge and I came here to ask people for help.

I will try to explain what my project needs to do;

There will be 4 buttons; start, finish, shipping and check. These buttons basically all are steps for editing a Ticket. (as this is a ticket log)

So; Once the user clicks on any of the buttons, I want a popup to come with one input field. In this input field we use a barcode scanner to input the Ticket_ID and then edit the ticket. But the catch is that it has to go to the right ticket, and the right edit form. (based upon the clicked button)

I could create a seperate view for every button, but I feel like I could do it easier if I'd just use an if statement in my form view to detect which button was pressed. But I am not sure if this is better.

So, My questions:

a) How can I make the popup with a search form? b) How should I redirect to the right form? (one view, multiple views?)

21 Aug
2 months ago

woxene started a new conversation Checking Database Value And Echoing A String To Screen.

My database table can have 2 kind of values dt and transport. To show the data in my view I use the following : <td>{{ $transportDTAccount->type }}</td>

The problem is that I would like to have it a little more readable. When the data is dt I would like Laravel to echo Duties & Taxes and when the data is transport I would like Laravel to echo Transport (<- This is capitalized).

Can someone tell me how I can achieve this kind of if statement for my view?

20 Aug
2 months ago

woxene left a reply on Checking Current URL For Active Class

Thanks everyone for replying. It was a JS library I added editing the active classes on it's own. My first script already works.

woxene left a reply on Checking Current URL For Active Class

Hey @vivekdhumal, unfortunately that doesn't solve the problem. Any other suggestions?

woxene started a new conversation Checking Current URL For Active Class

I am trying to add an class='active' attribute to my menu when you are on this current page. I can't seem to get this to work. Here is my code:

@if(Request::is('tickets*'))
    <ul class="tabs tabs-transparent tabs-fixed-width">
        <li class="tab"><a target="_self" href="{{ route('tickets.create') }}" @if(Request::is('tickets/create')) class='active' @endif>Ticket Entry</a></li>
    </ul>
@endif

The first If statement makes sure this menu only shows when you are in the tickets area of the website.

My url is http://127.0.0.1:8000/tickets/create and it does not add the class active.

16 Aug
2 months ago

woxene left a reply on Form To URL

I fixed that. I was forgetting @csrf in my form. Now I need to know how to write my controller function : Get the ID that belongs to the name. and then redirect to the page where you can see the details of it.

woxene left a reply on Form To URL

Thank you. But now I get an error The page has expired due to inactivity. Please refresh and try again.

woxene started a new conversation Form To URL

I need a simple functionality from my form input to go in the url. I can't seem to get it to work.

I have an input where you can select a country name.

<form method="POST" action="IDK WHAT THIS SHOULD BE">
    <input type="text" id="autocomplete-input" class="autocomplete">
    <label for="autocomplete-input">Autocomplete</label>
    <input type="submit" value="Send">
</form>

This data needs to go to the controller. The controller is CountryController and my route is Route::post('countries/search', '[email protected]');

The controller needs to find out the ID that belongs to the submitted data. The controller needs to redirect to the url with the previously found ID.

This is everything my controller function has so far:

public function search(Request $request)
{
    $name = $request->input('country_name');
//get id by name
//redirect to /countries/{id}
}
03 Aug
3 months ago

woxene left a reply on Laravel 5.6 Register Doesn't Work, No Redirect And No Errors (edited Register Fields)

Thank you!!!! That's it. I actually FORGOT to make a field for contract_type. Thats why there was an error. Thanks!

woxene left a reply on Laravel 5.6 Register Doesn't Work, No Redirect And No Errors (edited Register Fields)

@saurabhd I removed one of the routes (the one I didn't need) And the problem remains the same. Any idea?

woxene left a reply on Laravel 5.6 Register Doesn't Work, No Redirect And No Errors (edited Register Fields)

@36864 Thank you for your answer. I tried it and my page refreshes without any error message. Nothing was saved to the database.. All value="{{ old('name') }}" date came back to the form.

woxene left a reply on Laravel 5.6 Register Doesn't Work, No Redirect And No Errors (edited Register Fields)

I updated it!

Also, I ran return response()->json($request) in the registercontroller and I got this result:

"_token": "5GwdLhezd2EeKQYQYcn0cYT47NxlK6zzVGPwqTsj",
"name": "testname",
"lastname": "testlast",
"initials": "tt",
"email": "[email protected]",
"password": "testpassword",
"password_confirmation": "testpasssword",
"mobile_number": "0612345678",
"emergency_number": "0612345678",
"date_of_birth": "22-8-2018",
"function": "teamleader",
"reachtruck_cert": "0",
"reachtruck_cert_expiry_date": null,
"forklift_cert": "0",
"forklift_cert_expiry_date": null
}```

woxene left a reply on Laravel 5.6 Register Doesn't Work, No Redirect And No Errors (edited Register Fields)

I am sorry, I know! I fixed that already. I still have the same problem tho!

woxene started a new conversation Laravel 5.6 Register Doesn't Work, No Redirect And No Errors (edited Register Fields)

For my project I was required to change the default php artisan make:auth User database + registration form. I've got everything ready, but something seems off.

Validation works. Because I do get errors for this. But when I pass the Validation function nothing seems to happen. I just get a refresh where I keep all fields with value="{{ old('name') }}" and nothing gets added to the database nor do I get an error message.

Here are some of my files:

Web.php(routes):

<?php
Auth::routes();

//    MAIN
Route::get('/', '[email protected]')->name('home');
Route::get('/home', '[email protected]')->name('home');

//    CRUD CONTROLLERS
Route::resource('users','UserController');

register.blade.php:

<div class="row">
<div class="col card hoverable s12">
    <div class="card-content">
        <form method="POST" action="{{ route('register') }}" aria-label="{{ __('Register') }}">
            @csrf
            <span class="card-title">Add Employee<a class="waves-effect waves-light hoverable btn white-text right" href="{{ route('users.index') }}"><i
                            class="material-icons">arrow_back</i></a></span>
            <div class="row">
                <div class="input-field col s4">
                    <label for="name">Name</label>
                    <input id="name" class="{{ $errors->has('name') ? ' invalid' : '' }}" type="text" value="{{ old('name') }}" name="name" required>
                    @if ($errors->has('name'))
                        <script>M.toast({html: '{{ $errors->first('name') }}'})</script>
                    @endif
                </div>
                <div class="input-field col s4">
                    <label for="lastname">Last Name</label>
                    <input id="lastname" class="{{ $errors->has('lastname') ? ' invalid' : '' }}" type="text" value="{{ old('lastname') }}" name="lastname" required>
                    @if ($errors->has('lastname'))
                        <script>M.toast({html: '{{ $errors->first('lastname') }}'})</script>
                    @endif
                </div>
                <div class="input-field col s4">
                    <label for="initials">Initials</label>
                    <input id="initials" class="{{ $errors->has('initials') ? ' invalid' : '' }}" type="text" value="{{ old('initials') }}" name="initials" required>
                    @if ($errors->has('initials'))
                        <script>M.toast({html: '{{ $errors->first('initials') }}'})</script>
                    @endif
                </div>
            </div>
            <div class="row">
                <div class="input-field col s4">
                    <label for="email">E-Mail</label>
                    <input id="email" class="{{ $errors->has('email') ? ' invalid' : '' }}" type="email" value="{{ old('email') }}" name="email" required>
                    @if ($errors->has('email'))
                        <script>M.toast({html: '{{ $errors->first('email') }}'})</script>
                    @endif
                </div>
                <div class="input-field col s4">
                    <label for="password">Password</label>
                    <input id="password" class="{{ $errors->has('password') ? ' invalid' : '' }}" type="password" value="{{ old('password') }}" name="password" required>
                    @if ($errors->has('password'))
                        <script>M.toast({html: '{{ $errors->first('password') }}'})</script>
                    @endif
                </div>
                <div class="input-field col s4">
                    <label for="password_confirmation">Confirm Password</label>
                    <input id="password_confirmation" class="{{ $errors->has('password_confirmation') ? ' invalid' : '' }}" type="password" name="password_confirmation"
                           required>
                    @if ($errors->has('password_confirmation'))
                        <script>M.toast({html: '{{ $errors->first('password_confirmation') }}'})</script>
                    @endif
                </div>
            </div>
            <div class="row">
                <div class="input-field col s6">
                    <label for="mobile_number">Mobile Number</label>
                    <input id="mobile_number" class="{{ $errors->has('mobile_number') ? ' invalid' : '' }}" type="number" value="{{ old('mobile_number') }}" name="mobile_number"
                           required>
                    @if ($errors->has('mobile_number'))
                        <script>M.toast({html: '{{ $errors->first('mobile_number') }}'})</script>
                    @endif
                </div>
                <div class="input-field col s6">
                    <label for="emergency_number">Emergency Number</label>
                    <input id="emergency_number" class="{{ $errors->has('emergency_number') ? ' invalid' : '' }}" type="number" value="{{ old('emergency_number') }}" name="emergency_number"
                           required>
                    @if ($errors->has('emergency_number'))
                        <script>M.toast({html: '{{ $errors->first('emergency_number') }}'})</script>
                    @endif
                </div>
            </div>
            <div class="row">
                <div class="input-field col s6">
                    <label for="date_of_birth">Date of Birth</label>
                    <input id="date_of_birth" class="{{ $errors->has('date_of_birth') ? ' invalid' : '' }} datepicker" type="text" value="{{ old('date_of_birth') }}" name="date_of_birth"
                           required>
                    @if ($errors->has('date_of_birth'))
                        <script>M.toast({html: '{{ $errors->first('date_of_birth') }}'})</script>
                    @endif
                </div>
                <div class="input-field col s6">
                    <select id="function" name="function">
                        <option value="" disabled selected>Choose a Function</option>
                        <option value="teamleader">Team Leader</option>
                        <option value="trafficdesk">Trafficdesk</option>
                        <option value="foreman">Foreman</option>
                        <option value="warehouse_operator">Warehouse Operator</option>
                    </select>
                    @if ($errors->has('function'))
                        <script>M.toast({html: '{{ $errors->first('function') }}'})</script>
                    @endif
                    <label for="function">Function</label>
                </div>
            </div>
            <div class="row">
                <div class="input-field col s1">
                    <p class="left-align">Reachtruck Certificate?</p>
                </div>
                <div class="input-field col s1 offset-s1">
                    <label>
                        <input class="with-gap" name="reachtruck_cert" type="radio" value="1"/>
                        <span>Yes</span>
                    </label>
                </div>
                <div class="input-field col s3">
                    <label>
                        <input class="with-gap" name="reachtruck_cert" type="radio" value="0"/>
                        <span>No</span>
                    </label>
                    @if ($errors->has('reachtruck_cert'))
                        <script>M.toast({html: '{{ $errors->first('reachtruck_cert') }}'})</script>
                    @endif
                </div>
                <div class="input-field col s6">
                    <label for="reachtruck_cert_expiry_date">Reachtruck Certificate Expiry Date</label>
                    <input id="reachtruck_cert_expiry_date" class="{{ $errors->has('reachtruck_cert_expiry_date') ? ' invalid' : '' }} datepicker" type="text"
                           value="{{ old('reachtruck_cert_expiry_date') }}" name="reachtruck_cert_expiry_date">
                    @if ($errors->has('reachtruck_cert_expiry_date'))
                        <script>M.toast({html: '{{ $errors->first('reachtruck_cert_expiry_date') }}'})</script>
                    @endif
                </div>
            </div>
            <div class="row">
                <div class="input-field col s1">
                    <p class="left-align">Forklift Certificate?</p>
                </div>
                <div class="input-field col s1 offset-s1">
                    <label>
                        <input class="with-gap" name="Forklift_cert" type="radio" value="1"/>
                        <span>Yes</span>
                    </label>
                </div>
                <div class="input-field col s3">
                    <label>
                        <input class="with-gap" name="Forklift_cert" type="radio" value="0"/>
                        <span>No</span>
                    </label>
                    @if ($errors->has('Forklift_cert'))
                        <script>M.toast({html: '{{ $errors->first('Forklift_cert') }}'})</script>
                    @endif
                </div>
                <div class="input-field col s6">
                    <label for="forklift_cert_expiry_date">Forklift Certificate Expiry Date</label>
                    <input id="forklift_cert_expiry_date" class="{{ $errors->has('forklift_cert_expiry_date') ? ' invalid' : '' }} datepicker" type="text"
                           value="{{ old('forklift_cert_expiry_date') }}" name="forklift_cert_expiry_date">
                    @if ($errors->has('forklift_cert_expiry_date'))
                        <script>M.toast({html: '{{ $errors->first('forklift_cert_expiry_date') }}'})</script>
                    @endif
                </div>
            </div>
            <div class="card-action right-align">
                <button class="waves-effect waves-light btn-small hoverable" type="submit">Add Employee</button>
            </div>
        </form>
    </div>
</div>

RegisterController.php:

namespace App\Http\Controllers\Auth;
use App\User;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Validator;
use Illuminate\Foundation\Auth\RegistersUsers;
class RegisterController extends Controller
{


use RegistersUsers;

/**
 * Where to redirect users after registration.
 *
 * @var string
 */
protected $redirectTo = '/users';

/**
 * Create a new controller instance.
 *
 * @return void
 */
public function __construct()
{
    $this->middleware('auth');
}

/**
 * Get a validator for an incoming registration request.
 *
 * @param  array $data
 * @return \Illuminate\Contracts\Validation\Validator
 */
protected function validator(array $data)
{
    return Validator::make($data, [
        'name'             => 'required|string|max:255',
        'lastname'         => 'required|string|max:255',
        'initials'         => 'required|string|max:10',
        'email'            => 'required|string|email|max:255|unique:users',
        'password'         => 'required|string|min:6|confirmed',
        'mobile_number'    => 'required|string|max:25',
        'emergency_number' => 'required|string|max:25',
        'date_of_birth'    => 'required|date',
        'contract_type'    => 'required|string|max:50',
        'function'         => 'required|string|max:50',
        'reachtruck_cert'  => 'required|integer',
        'forklift_cert'    => 'required|integer',
    ]);
}

/**
 * Create a new user instance after a valid registration.
 *
 * @param  array $data
 * @return \App\User
 */
protected function create(array $data)
{
    return User::create([
        'name'                        => $data['name'],
        'lastname'                    => $data['lastname'],
        'initials'                    => $data['initials'],
        'email'                       => $data['email'],
        'password'                    => Hash::make($data['password']),
        'mobile_number'               => $data['mobile_number'],
        'emergency_number'            => $data['emergency_number'],
        'date_of_birth'               => $data['date_of_birth'],
        'contract_type'               => $data['contract_type'],
        'function'                    => $data['function'],
        'reachtruck_cert'             => $data['reachtruck_cert'],
        'reachtruck_cert_expiry_date' => $data['reachtruck_cert_expiry_date'],
        'forklift_cert'               => $data['forklift_cert'],
        'forklift_cert_expiry_date'   => $data['forklift_cert_expiry_date'],
    ]);
}
}

User model:

namespace App;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable
{
    use Notifiable;
    
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'name',
        'lastname',
        'initials',
        'email',
        'password',
        'mobile_number',
        'emergency_number',
        'date_of_birth',
        'contract_type',
        'function',
        'reachtruck_cert',
        'reachtruck_cert_expiry_date',
        'forklift_cert',
        'forklift_cert_expiry_date',
    ];
    
    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = [
        'password',
        'remember_token',
    ];
    
}

php artisan route:list

+--------+-----------+------------------------+------------------+------------------------------------------------------------------------+--------------+
| Domain | Method    | URI                    | Name             | Action                                                                 | Middleware   |
+--------+-----------+------------------------+------------------+------------------------------------------------------------------------+--------------+
|        | GET|HEAD  | /                      | home             | App\Http\Controllers\[email protected]                              | web,auth     |
|        | GET|HEAD  | api/user               |                  | Closure                                                                | api,auth:api |
|        | GET|HEAD  | home                   | home             | App\Http\Controllers\[email protected]                              | web,auth     |
|        | POST      | login                  |                  | App\Http\Controllers\Auth\[email protected]                        | web,guest    |
|        | GET|HEAD  | login                  | login            | App\Http\Controllers\Auth\[email protected]                | web,guest    |
|        | POST      | logout                 | logout           | App\Http\Controllers\Auth\[email protected]                       | web          |
|        | POST      | password/email         | password.email   | App\Http\Controllers\Auth\[email protected]  | web,guest    |
|        | POST      | password/reset         |                  | App\Http\Controllers\Auth\[email protected]                | web,guest    |
|        | GET|HEAD  | password/reset         | password.request | App\Http\Controllers\Auth\[email protected] | web,guest    |
|        | GET|HEAD  | password/reset/{token} | password.reset   | App\Http\Controllers\Auth\[email protected]        | web,guest    |
|        | POST      | register               |                  | App\Http\Controllers\Auth\[email protected]                  | web,auth     |
|        | GET|HEAD  | register               | register         | App\Http\Controllers\Auth\[email protected]      | web,auth     |
|        | GET|HEAD  | users                  | users.index      | App\Http\Controllers\[email protected]                              | web          |
|        | POST      | users                  | users.store      | App\Http\Controllers\[email protected]                              | web          |
|        | GET|HEAD  | users/create           | users.create     | App\Http\Controllers\[email protected]                             | web          |
|        | GET|HEAD  | users/{user}           | users.show       | App\Http\Controllers\[email protected]                               | web          |
|        | PUT|PATCH | users/{user}           | users.update     | App\Http\Controllers\[email protected]                             | web          |
|        | DELETE    | users/{user}           | users.destroy    | App\Http\Controllers\[email protected]                            | web          |
|        | GET|HEAD  | users/{user}/edit      | users.edit       | App\Http\Controllers\[email protected]                               | web          |
+--------+-----------+------------------------+------------------+------------------------------------------------------------------------+--------------+

And last (even though I don't think it has something to do with my problem because my register.blade.php sends it directly to the registercontroller.) I will show my UserController;

namespace App\Http\Controllers;
use App\User;
use Illuminate\Http\Request;
/**
 * Class UserController
 * @package App\Http\Controllers
 */
class UserController extends Controller
{
    
    /**
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
     */
    public function index()
    {
        $users = User::latest()->paginate(5);
        
        
        return view('users.index', compact('users'))->with('i', (request()->input('page', 1) - 1) * 5);
    }
    
    
    /**
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
     */
    public function create()
    {
        return view('auth.register');
    }
    
    
    /**
     * @param Request $request
     */
    public function store(Request $request)
    {
        // Not using this here.
    }
    
    
    /**
     * @param User $user
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
     */
    public function show(User $user)
    {
        return view('users.show', compact('user'));
    }
    
    
    /**
     * @param User $user
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
     */
    public function edit(User $user)
    {
        return view('users.edit', compact('user'));
    }
    
    
    /**
     * @param Request $request
     * @param User $user
     * @return \Illuminate\Http\RedirectResponse
     */
    public function update(Request $request, User $user)
    {
        request()->validate([
            'name'             => 'required|string|max:255',
            'lastname'         => 'required|string|max:255',
            'initials'         => 'required|string|max:10',
            'email'            => 'required|string|email|max:255',
            'mobile_number'    => 'required|string|max:25',
            'emergency_number' => 'required|string|max:25',
            'date_of_birth'    => 'required|date',
            'contract_type'    => 'required|string|max:50',
            'function'         => 'required|string|max:50',
            'reachtruck_cert'  => 'required|integer',
            'forklift_cert'    => 'required|integer',
        ]);
        
        
        $user->update($request->all());
        return redirect()->route('users.index')->with('success', 'Employee updated successfully');
    }
    
    
    /**
     * @param User $user
     * @return \Illuminate\Http\RedirectResponse
     * @throws \Exception
     */
    public function destroy(User $user)
    {
        $user->delete();
        return redirect()->route('users.index')->with('success', 'Employee deleted successfully');
    }
}

Is there anyone that could assist me with my problem? I'm stuck on this for some hours now. If you need any more files let me know and I will update this post.