ajsmith_codes

ajsmith_codes

Member Since 1 Year Ago

Experience Points
17,720
Total
Experience

2,280 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
111
Lessons
Completed
Best Reply Awards
0
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.

Level 4
17,720 XP
Oct
12
1 week ago
Activity icon

Replied to Vue - Tell Parent To Run Method On Close Of Child.

Thanks for the guidance. I was able to find a tutorial for a simple test of parent/child communication and I got it to work!

Call Parent Method from Child Component in Vue Js

Activity icon

Replied to Vue - Tell Parent To Run Method On Close Of Child.

As soon as I add the to the parent, it stops working. I'm using VueJSModal if that makes a difference.

Activity icon

Started a new Conversation Vue - Tell Parent To Run Method On Close Of Child.

I have a form to create a new Sales Order. If the Customer is not showing up, I want the user to open a modal and create the Customer. No problem so far.

Now, after the Customer has been created, the modal closes. I'm having trouble getting the parent to update the Customers field to include the new Customer.

As it is now, the customer is created, but the modal doesn't close anymore and the parent doesn't update.

Here are the key parts of the parent: form:

                                    <select
                                        class='form-control'
                                        style="padding-left:60px;"
                                        v-model='customer'
                                        @updateCustomers="updateCustomers"
                                        id="contact">
                                        <option
                                            value='0'
                                            disabled>
                                            Select
                                            Customer
                                        </option>
                                        <option
                                            v-for='customer in customers'
                                            :value='customer.id'>
                                            {{
                                                customer.name
                                            }}
                                        </option>
                                    </select>
                                    <button
                                        type="button"
                                        class="btn custom-page-link"
                                        @click="$modal.show('new-customer')">
                                        New
                                        Customer
                                    </button>
                                    <new-customer @finished="updateCustomers"></new-customer>

                                </div>

code below in parent:

import NewCustomer from "../customers/NewCustomer";

export default { component() { NewCustomer }, data: function () { return { errors: [], orderNumber: '', customers: [], customer: '' }; }, methods: { addSalesorder(e) { if (this.orderNumber) { axios.post('/salesorders/new', { orderNumber: this.orderNumber, }) .then((response) => { swal( { title: 'Created!', text: 'Order has been created.', type: 'success' } ) .then((ok) => { if (ok) { //this.modalShow = false window.close() } }); // this.modalShow = false // window.location.reload() }) .catch(error => { console.log(error) }); }

    },
    updateCustomers(customers) {
        axios.get('/api/getCustomers')
            .then(function (response) {
                this.customers = response.data;
            }.bind(this));
    }
},
mounted() {
    axios.get('/api/getCustomers')
        .then(function (response) {
            this.customers = response.data;
        }.bind(this));
},

};

Child: Submit <button type="button" class="btn custom-page-link" @click="$modal.hide('new-customer')"> Cancel

export default { data: function () { return { // contactType: 0, // types: [], name: '', phone: '', errors: [], modalShow: true, email: '', note: '', contactName: '', contactNote: '' }; }, methods: { addCustomer(e) { if (this.name) { axios.post('/salesorders/customer/create', { // type: this.contactType, phone: this.phone, name: this.name, email: this.email, note: this.note, contactName: this.contactName, contactNote: this.contactNote }) .then((response) => { swal( { title: 'Created!', text: 'Customer has been created.', type: 'success' } ) .then((ok) => { if (ok) { this.modalShow = false // window.location.reload() // addToSalesOrder(); // this.$emit('finished'); } }); // this.modalShow = false // window.location.reload() }) .catch(error => { console.log(error) }); }

        this.errors = [];

        if (!this.name) {
            this.errors.push('Please enter a Customer Name.');
        }
        if(!this.contactName){
            this.errors.push('Please enter a Contact Name.');
        }

    },
},
mounted() {
    axios.get('/api/getContactTypes')
        .then(function (response) {
            this.types = response.data;
        }.bind(this));
},

};

Oct
07
2 weeks ago
Activity icon

Started a new Conversation Help With Displaying Collection In View.

I am trying to get my results to work in a view, but I'm missing something.

Here is the query:

    $employees = DB::table('employees')
        ->where('employees.supervisor_id', '=', $employee->id)
        ->join('departments', 'departments.id', '=', 'employees.pto_department_id')
        ->join('users', 'users.id', '=', 'employees.user_id')
        ->select('users.name as first_name', 'employees.*', 'departments.name as name')
        ->get()
        ->groupBy('name');

In the view, I do this:

                <ul>
                    @foreach( $employees as $dept)

                        <li>
                            {{ $dept }}:
                            
                        </li>
                    @endforeach
                </ul>

And get a collection. I can't figure out how to get it to display with a foreach.

Here is my current output in the blade, with sensitive details removed:

[{"first_name":"AJ","id":2,"user_id":1,"active":1,"department_id":3,"pto_department_id":3,supervisor_id":1,"name":"Sales"}, {"first_name":"Joe","id":23,"user_id":23,"active":1,"department_id":3,"pto_department_id":3,"supervisor_id":1,"name":"Sales"}]

[{"first_name":"Nathan","id":4,"user_id":4,"active":1,"department_id":4,"pto_department_id":12,"supervisor_id":1,"name":"Supervisor"}]

Oct
01
3 weeks ago
Activity icon

Replied to Pass Data From Vue Modal To Laravel View?

Hi, @a4ashraf I am trying this now, but I am having trouble getting it to work.

Here is what I have in the controller:

 JavaScript::put([
        'customer' => $customer,
        'contact' => $contact,
    ]);

I am looking in the footer where these are supposed to populate, but nothing is showing.

EDIT: I am running the code after saving the customer and contact, then I close the modal.

Activity icon

Started a new Conversation Pass Data From Vue Modal To Laravel View?

Is it possible to pass data from a modal when it closes and have it populate into a form in a view?

For example, I have a form where a user can enter a new Sales Order. It lists the current customers but also has a link to a modal window where a new customer can be entered. After submitting the form and closing the modal window, I would like the new customer to populate in the customer dropdown.

The only way I can think of is to use JavaScript and watch for the modal to close.

Any other way to do this?

Sep
30
3 weeks ago
Activity icon

Replied to Conditional CSS Classes In Blade - Possible To Use OR?

Sorry, that's what I meant.

Activity icon

Started a new Conversation Conditional CSS Classes In Blade - Possible To Use OR?

Is it possible to make the first link bold if it's "/customers" without "/?active=1" OR "/?active=0"? I was trying to make it an OR statement, but couldn't get it to work.

a href="/customers" class="{{ ??? }}">All

a href="/customers/?active=1" class="{{ strpos($_SERVER['REQUEST_URI'], 'active=1') !== false ? 'font-weight-bold' : '' }}">Active

a href="/customers/?active=0" class="{{ strpos($_SERVER['REQUEST_URI'], 'active=0') !== false ? 'font-weight-bold' : '' }}">Inactive

Sep
29
3 weeks ago
Activity icon

Replied to Upgrade To Laravel To 8.x Failed

@kaiserkais How did you update Illuminate/Support? I can't find any documentation on that.

Activity icon

Replied to Get Name In Blade View Without Relationship?

@snapey Sorry, I completely missed that second line of code in your comment. I tried it and it works great. Thank you!

Activity icon

Replied to Get Name In Blade View Without Relationship?

Illuminate\Support\Collection {#1619 ▼ #items: array:4 [▼ 1 => "Order Entry" 2 => "Design" 3 => "Sales" 4 => "Shipping & Receiving" ] }

Activity icon

Replied to Get Name In Blade View Without Relationship?

Here is how I get activity:

    $activities =  Activity::query()
        ->where(function (\Illuminate\Database\Eloquent\Builder $query) use ($order) {
            $query
                ->where(function (\Illuminate\Database\Eloquent\Builder $q) use ($order) {
                    $q
                        ->where('subject_type', $order->getMorphClass())
                        ->where('subject_id', $order->getKey());
                })
                ->orWhere(function (\Illuminate\Database\Eloquent\Builder $q) use ($order) {
                    $q
                        ->where('subject_type', (new OrderNotes())->getMorphClass())
                        ->whereIn('subject_id', $order->notes()->pluck('id'));
                });
        })
        ->latest()
        ->get();

Then I pass it like this:

return view('salesorders.show', compact('order', 'notes', 'generalNotes', 'departments'))->with(['activities' => $activities]);

Activity icon

Replied to Get Name In Blade View Without Relationship?

@snapey Here is the code in the view:

$activity->changes['old'][$key]

How do I make it work? I tried this:

$departments[$key]

But get Undefined Index. $key is the department_id in this case.

EDIT: Here is the full content of the properties I retrieve from activity:

{"attributes":{"department_id":2},"old":{"department_id":1}}

Activity icon

Replied to Get Name In Blade View Without Relationship?

@snapey I thought about that but wasn't sure how to do a lookup in a blade.

@msslgomez How would you implement that with the current query I have?

    $activities =  Activity::query()
        ->where(function (\Illuminate\Database\Eloquent\Builder $query) use ($order) {
            $query
                ->where(function (\Illuminate\Database\Eloquent\Builder $q) use ($order) {
                    $q
                        ->where('subject_type', $order->getMorphClass())
                        ->where('subject_id', $order->getKey());
                })
                ->orWhere(function (\Illuminate\Database\Eloquent\Builder $q) use ($order) {
                    $q
                        ->where('subject_type', (new OrderNotes())->getMorphClass())
                        ->whereIn('subject_id', $order->notes()->pluck('id'));
                });
        })
        ->latest()
        ->get();
Sep
28
3 weeks ago
Activity icon

Started a new Conversation Get Name In Blade View Without Relationship?

I'm not sure how to word this correctly.

I am using Spatie Activity log. It works great, except it logs the department_id not the name of the department. When showing the log in a blade view, how would I retrieve the name of the department?

For example, I change a department from Sales to Shipping I get this for the activity:

{"attributes":{"department_id":1},"old":{"department_id":4}}

Unless someone knows how to override the department_id when activity is logged?

Sep
25
1 month ago
Activity icon

Replied to How To Handle Error 1062 Duplicate Key Entry For Composite Key?

I came up with a solution:

    try {

        $order->contact()->attach($contact);

    } catch (\Exception $e) {

        throw \Illuminate\Validation\ValidationException::withMessages([
            'contact_id' => 'This person is already assigned to the order.',
        ]);
    }
Activity icon

Replied to How To Handle Error 1062 Duplicate Key Entry For Composite Key?

@jlrdw That's starting to make sense to me. Can you give me an idea on the table structure of the child? I'm still stuck on visualizing many to many.

Activity icon

Replied to How To Handle Error 1062 Duplicate Key Entry For Composite Key?

@geninoliveira No, I will check that out.

@jlrdw I am a bit confused about your suggestion. How would you set up the line items table?

Here is what I have currently:

Orders (as in Sales orders): id customer_id etc.

CustomerContacts: id customer_id etc.

OrderContacts: as seen in previous post.

Activity icon

Started a new Conversation How To Handle Error 1062 Duplicate Key Entry For Composite Key?

Each Order can have many Contacts. Each Contact can belong to many Orders.

I'm trying to avoid duplicates here and I set up the table as many to many. The only thing I could get to work was creating a composite key. However, I can't seem to find a way to handle validation error and get 1062 instead of a message to the user.

Table:

  $table->unique(['contact_id', 'order_id']);
  $table->unsignedBigInteger('contact_id');
  $table->foreignId('order_id');
  $table->timestamps();
  $table->foreign('contact_id')->references('id')->on('customer_contacts');
Activity icon

Replied to Solved: Ajax Request Data Returns As Object - How To Populate Multiple Inputs?

I did try that out of curiosity and it didn't work. Weird!

Activity icon

Replied to Solved: Ajax Request Data Returns As Object - How To Populate Multiple Inputs?

I'm not certain why it does that either.

I'm not sure which answer to pick as "Best Answer" since none of them are dead on.

Activity icon

Replied to Solved: Ajax Request Data Returns As Object - How To Populate Multiple Inputs?

It's working! I changed

    return json_encode(  (array)$data );

To:

return response()->json($data);

And this is the JS code:

        $('input[name="email"]').val(data[0].email);
                $('input[name="number"]').val(data[0].phone);
Activity icon

Replied to Solved: Ajax Request Data Returns As Object - How To Populate Multiple Inputs?

I get:

Uncaught TypeError: Cannot read property 'phone' of undefined

Activity icon

Replied to Solved: Ajax Request Data Returns As Object - How To Populate Multiple Inputs?

The strange thing is that I didn't get anything by using console.log. I only get the error.

EDIT: I commented out the input code and was able to see the console.log info:

{*items: Array(1)} *items: Array(1) 0: active: 1 created_at: "2020-09-25 08:35:55" customer_id: 1 deleted_at: null email: "[email protected]" id: 1 name: "Alfredo Nitzsche" phone: "(759) 475-5822 x550" slug: "aut-aperiam-ipsum" type: "Main" updated_at: "2020-09-25 08:35:55" proto: Object length: 1 proto: Array(0) proto: Object

Activity icon

Replied to Solved: Ajax Request Data Returns As Object - How To Populate Multiple Inputs?

Sorry, no. I get:

    at Object.success (custom.js:174)
    at fire (app.js:65779)
    at Object.fireWith [as resolveWith] (app.js:65909)
    at done (app.js:72069)
    at XMLHttpRequest.<anonymous> (app.js:72330)
Activity icon

Replied to Solved: Ajax Request Data Returns As Object - How To Populate Multiple Inputs?

When using this:

$data = DB::table('customer_contacts')->where("id",$id)->get();

    return json_encode(  (array)$data );

I get this back when I do a console.info(data):

{*items: Array(1)} *items: Array(1) 0: {id: 1, customer_id: 1, type: "Main", name: "Alfredo Nitzsche", email: "[email protected]", …} length: 1 proto: Array(0)

Activity icon

Replied to Solved: Ajax Request Data Returns As Object - How To Populate Multiple Inputs?

Sure. Here are the two input fields. If I send two ajax requests separately, it works fine. It's when I send one request for two pieces of data.

                            <label
                                class="col-form-label font-weight-bold {{ $errors->has('number') ? 'text-danger' : '' }}">

                                Phone

                            </label>

                            <div
                                class="input-group">

                                <input
                                    class="form-control {{ $errors->has('number') ? 'border-danger' : '' }}"
                                    id="number"
                                    type="text"
                                    name="number"
                                    value="{{ $contact->phone ? $contact->phone : old('number') }}">
                                <div
                                    class="input-group-append">
                                                <span
                                                    class="input-group-text">

                                                    <input
                                                        type="checkbox"
                                                        class="mr-1"
                                                        name="deletePhone"
                                                        value="1"
                                                    >
                                                    <span
                                                        class="error">Delete</span>
                                                </span>

                                </div>

                            </div>

                            @error('number')
                            <p class="error">{{ $message }}</p>
                            @enderror

                        </div>

                        <div
                            class="form-group">

                            <label
                                class="col-form-label font-weight-bold {{ $errors->has('email') ? 'text-danger' : '' }}">

                                Email

                            </label>

                            <div
                                class="input-group">


                                <input
                                    class="form-control {{ $errors->has('email') ? 'border-danger' : '' }}"
                                    id="email"
                                    type="email"
                                    name="email"

                                    value="{{ $contact->email ? $contact->email : old('email') }}">
                                <div
                                    class="input-group-append">
                                                <span
                                                    class="input-group-text">

                                                    <input
                                                        type="checkbox"
                                                        class="mr-1"
                                                        name="deleteEmail"
                                                        value="1"
                                                    >
                                                    <span
                                                        class="error">Delete</span>
                                                </span>

                                </div>
                            </div>

                            @error('email')
                            <p class="error">{{ $message }}</p>
                            @enderror

                        </div>
Activity icon

Replied to Solved: Ajax Request Data Returns As Object - How To Populate Multiple Inputs?

Darn. Thanks for trying! I don't have Team Viewer and this is a work project, so I'm not sure I would be allowed to do that. I can, however, share it via github if you want.

Activity icon

Replied to Solved: Ajax Request Data Returns As Object - How To Populate Multiple Inputs?

I'm not sure why none of these are not working. If I make two separate ajax calls, it works.

$('select[name="contact_id"]').on('change', function () {

    var contact_id = $(this).val();

    if (contact_id) {
        $.ajax({
            url: '/api/contact/getEmail/' + contact_id,
            type: "GET",
            dataType: "json",
            beforeSend: function () {
                $('#loader').css("visibility", "visible");
            },

            success: function (data) {
                $('input[name="email"]').val(data);
            },
            complete: function () {
                $('#loader').css("visibility", "hidden");
            },
            error : function(){
                alert('Some error occurred!');
            }
        });
        $.ajax({
            url: '/api/contact/getPhone/' + contact_id,
            type: "GET",
            dataType: "json",
            beforeSend: function () {
                $('#loader').css("visibility", "visible");
            },
            success: function (data) {
                $('input[name="number"]').val(data);
            },
            complete: function () {
                $('#loader').css("visibility", "hidden");
            },
            error : function(){
                alert('Some error occurred!');
            }
        });
    } else {
        $('select[name="contact_id"]').empty();
    }

});
Activity icon

Replied to Solved: Ajax Request Data Returns As Object - How To Populate Multiple Inputs?

I didn't see that code before. I just tried it and got a popup that says "some error occurred" and gives me a 500.

Activity icon

Replied to Solved: Ajax Request Data Returns As Object - How To Populate Multiple Inputs?

Email comes back as undefined. The data comes back like this:

data [{"id":1,"customer_id":1,"type":"Main","name":"Alfredo Nitzsche","email":"[email protected]","phone":"(759) 475-5822 x550","active":1,"slug":"aut-aperiam-ipsum","created_at":"2020-09-25 08:35:55","updated_at":"2020-09-25 08:35:55","deleted_at":null}]

Activity icon

Replied to Solved: Ajax Request Data Returns As Object - How To Populate Multiple Inputs?

Sorry about that. :)

Here is the JS code that is in a file on it's own:

$('select[name="contact_id"]').on('change', function () {

    var contact_id = $(this).val();

    if (contact_id) {
        $.ajax({
            url: '/api/contact/get/' + contact_id,
            type: "GET",
            dataType: "json",
            beforeSend: function () {
                $('#loader').css("visibility", "visible");
            },

            success: function (data) {


                $('input[name="email"]').val(data.email);
                $('input[name="number"]').val(data["phone"]);

                console.info(data.email);

            },
            complete: function () {
                $('#loader').css("visibility", "hidden");
            },
            error : function(){
                alert('Some error occurred!');
            }
        });
    } else {
        $('select[name="contact_id"]').empty();
    }

});

Here is the Controller:

public function getContact($id){

    $data = DB::table('customer_contacts')->where("id",$id)
    ->get();

    return json_encode($data);

}
Activity icon

Replied to Solved: Ajax Request Data Returns As Object - How To Populate Multiple Inputs?

I tried to place your code in the success function, but it wouldn't work. I did this instead:

console.info(data.email);

That came back undefined, so I just did console.info(data);

[{…}] 0: {id: 1, customer_id: 1, type: "Main", name: "Alfredo Nitzsche", email: "[email protected]e.org", …} length: 1

Activity icon

Replied to Solved: Ajax Request Data Returns As Object - How To Populate Multiple Inputs?

[{"id":1,"customer_id":1,"type":"Main","name":"Alfredo Nitzsche","email":"[email protected]","phone":"(759) 475-5822 x550","active":1,"slug":"aut-aperiam-ipsum","created_at":"2020-09-25 08:35:55","updated_at":"2020-09-25 08:35:55","deleted_at":null}]

Activity icon

Started a new Conversation Solved: Ajax Request Data Returns As Object - How To Populate Multiple Inputs?

I make an Ajax call to get contact data. I had it working where I was getting 1 piece of data: email. The returning data would populate into an input: $('input[name="email"]').val(data);

I now need to get Email and Phone. I can successfully get the data returned, but I can't seem to populate the two separate input fields.

If I do that now, I get an object. I then tried this but it doesn't work either:

$('input[name="email"]').val(data["email"]); $('input[name="number"]').val(data["phone"]);

What am I missing here?

Sep
18
1 month ago
Activity icon

Replied to One To Many Relationship - Polymorphic Or Regular?

Yes, I'm using Spatie's version.

I tried changing to 'department', but it still didn't work.

Here is the full code for the search:

    $sortBy = 'requested_ship_date';
    $orderBy = 'desc';
    $perPage = 5;
    $q = null;

    if ($request->has('orderBy')) $orderBy = $request->query('orderBy');
    if ($request->has('sortBy') && $request->sortBy !== 'requested ship date') $sortBy = $request->query('sortBy');
    if ($request->has('perPage')) $perPage = $request->query('perPage');
    if ($request->has('q')) $q = $request->query('q');

    $orders = Order::with('department')->search($q)->orderBy($sortBy, $orderBy)->paginate($perPage);

I got it from a tutorial online.

EDIT: It's working! I forgot to change something in the blade. Thanks for the help!!

Activity icon

Replied to One To Many Relationship - Polymorphic Or Regular?

If I use activity logging, I can still see who processed it and when. So if you take that out of the equation, it seems that a One to Many regular relationship would work, correct?

If so, how do I retrieve the relationship in the index view of orders? I tried the following, but it didn't work:

$orders = Order::with('departments')->search($q)->orderBy($sortBy, $orderBy)->paginate($perPage);

Activity icon

Replied to One To Many Relationship - Polymorphic Or Regular?

@ismaile

Lifecycle:

Department named Order Entry enters the order, then sends it to the next department. (An order can never be in more than one department at a time.)

The next department does their thing, then sends to the next. So on and so on.

Does that help?

Activity icon

Replied to One To Many Relationship - Polymorphic Or Regular?

@ismaile You are correct: Employees, Departments and Orders are separate tables. All departments have the same attributes: Name of dept and whether it's active.

I tried to setup as one to many regular, but couldn't get the name of the department to pull when showing all orders on the index page:

$order->department didn't work. $order->departments didn't work either.

Current Models...

Order: return $this->belongsTo('App\Models\Department');

Department: return $this->hasMany('App\Models\Order');

And tables...

Department: Id Name Type

Orders: Id department_id et.

Activity icon

Started a new Conversation One To Many Relationship - Polymorphic Or Regular?

My app has Departments. Each Employee belongs to a Department. Also, Sales Orders will be passed from department to department. I'm struggling with my database relationships here.

Do I make this Polymorphic? If so, what kind?

I'm probably overthinking this.

Sep
15
1 month ago
Activity icon

Replied to Help With Filter Using Pipelines. Laravel 7

Yes, it's a Date field. What's strange is that I copied the entire folder called QueryFilters and named it OrderFilters, then it worked. So, I think there is something I'm missing with the original code. It's most likely because I'm not 100% clear on how that code works.

The second return statement was from the code in the tutorial I followed by Coderstape.

Sep
14
1 month ago
Activity icon

Replied to Help With Filter Using Pipelines. Laravel 7

Where did you put that code? The model or controller? I watched the video, which is where I got the code from, but I'm not seeing the difference between what I coded and what he coded.

Activity icon

Started a new Conversation Help With Filter Using Pipelines. Laravel 7

I set up filters using the Laravel pipeline and it works great with sorting string data, but it doesn't work with dates. Any ideas as to why?

Here is a tutorial that is similar to what I did:

https://www.codechief.org/article/laravel-pipeline-interpretation-with-example

Model:

    return $orders = app(Pipeline::class)
        ->send(Order::query())
        ->through([
            \App\QueryFilters\Active::class,
            \App\QueryFilters\SortOrders::class,
            \App\QueryFilters\MaxCount::class
        ])
        ->thenReturn()->paginate(5);

Main Filter class:

    if (! request()->has($this->filterName())) {

        return $next($request);

    }

    $builder = $next($request);


    return $this->applyFilter($builder);


    return $builder->where('active', request('active'));

SortOrders class that extends Filter:

return $builder->orderBy('requested_ship_date', request($this->filterName()));

Sep
04
1 month ago
Activity icon

Replied to Keep Old Value Of Select - Ajax Based Edit Form.

Sorry, I was a bit unclear on the submit. I don't use ajax to submit. I only use it to get the states and cities.

I'll check out the link. Thanks!

Activity icon

Started a new Conversation Keep Old Value Of Select - Ajax Based Edit Form.

This is similar to another question I've asked, but there's a new twist to it.

Choose the country, it loads the states. Then choose the state and it loads the cities. Ajax based.

This is in an Edit form, so I also need to load the current value, if one exists, from the Customer's record.

So far so good. My problem is this:

If validation fails, I can only seem to retrieve the key of the select, not the value.

Here is the current form code:

{{ $customer->address ? $customer->address->country : '' }} @foreach ($countries as $country => $value) {{ $value }} @endforeach

Countries are pre-loaded in a variable from the Controller.

Here is the javascript code that runs when the select is changed:

$('select[name="country"]').on('change', function () {

    var countryId = $(this).val();

    if (countryId) {
        $.ajax({
            url: '/api/states/get/' + countryId,
            type: "GET",
            dataType: "json",
            beforeSend: function () {
                $('#loader').css("visibility", "visible");
            },

            success: function (data) {

                $('select[name="state"]').empty();

                $('select[name="state"]').append('<option value="Choose">Select State</option>');

                $.each(data, function (key, value) {

                    $('select[name="state"]').append('<option value="' + key + '">' + value + '</option>');

                });
            },
            complete: function () {
                $('#loader').css("visibility", "hidden");
            }
        });
    } else {
        $('select[name="state"]').empty();
    }

});

Any idea how to put the old value in? If I use old('country') I get the key, not the value.