Alex_B

Member Since 11 Months Ago

Experience Points
4,150
Total
Experience

850 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
22
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.

  • Community Pillar

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

Level 1
4,150 XP
Jun
10
2 days ago
Activity icon

Replied to How To Extra Data From API Call

Thank you so much. This is just what I needed.

Activity icon

Started a new Conversation How To Extra Data From API Call

I have a controller that makes an API call. I get a bunch of data back and I'm having a hard time sorting it out. Here is my function:

    public function getCandidates()
    {
        $this->setAccessToken();
        $this->setCompanyId();
        $this->setPositionId();
        $token = $this->getAccessToken();
        $companyId = $this->getCompanyId();
        $positionId = $this->getPositionId();
        $url = self::API_URL.'company/'.$companyId.'/position/'.$positionId.'/candidates';
        $withHeaders = ['headers' => ['Authorization' => $token]];
        try {
            $this->response = $this->client->get($url, $withHeaders);
            $candidates = json_decode($this->response->getBody()->getContents(), true);
        }
        catch (RequestException $e) {
            $this->response = $this->StatusCodeHandling($e);
        }
        $collection = collect($candidates)->map(function ($candidate){
            return [
                '_id' => $candidate['_id'],
                'meta_id' => $candidate['meta_id'],
//                'assigned_to' => $candidate['assigned_to'],  
                'creation_date' => $candidate['creation_date'] !== null ? Carbon::createFromFormat('Y-m-d\TH:i:s.u\Z', $candidate['creation_date']) : 'unknown',
                'email_address' => $candidate['email_address'],
                'headline' => $candidate['headline'],
                'initial' => $candidate['initial'],
                'name' => $candidate['name'],
                'origin' => $candidate['origin'],
                'phone_number' => $candidate['phone_number'],
//                'resume' => $candidate['resume'],
//                'source' => $candidate['source'],
                'stage' => $candidate['stage'],
                'tags' => $candidate['tags'],
                'overall_score' => $candidate['overall_score'],
                'updated_date' => $candidate['updated_date'] !== null ? Carbon::createFromFormat('Y-m-d\TH:i:s.u\Z', $candidate['updated_date']) : 'unknown',
            ];
        });
        return $collection;
    }

When I do dd($candidates) this is what I get:

candidates

and when I do dd($collection) this is what I get:

collection

First I need to access the data in the "stage" => array:3 [ …3] sitting inside the $candidates. How exactly can I do that?

edit: This first part I figured out.

Second why am i getting ErrorException Undefined array key "assigned_to" when I uncomment those lines in collection.

Third I'm trying to get rid of the T and Z that show up in the date values and am using this code 'creation_date' => $candidate['creation_date'] !== null ? Carbon::createFromFormat('Y-m-d\TH:i:s.u\Z', $candidate['creation_date']) : 'unknown' from one of the laracast tutorials here, but in my output I'm still seeing the T and Z show up.

Please correct me where I'm wrong. This is a multidimensional associative array that I'm returning $candidates and $collection is converting it to a collection, but this is what's throwing me off. Are the elements that are commented out storing other associative arrays in them? If yes, how can I access them or even know what they are?

Jun
05
1 week ago
Activity icon

Started a new Conversation Api Call With Guzzel In Lumen/Laravel

I'm new to using Guzzle in Lumen and I was hoping someone would be kind enough to review my attempt at making an API request. Below is a method in my controller.

public function getAccessToken()
    {
        $url = self::API_URL.'/signin';
        $data = ['email' => self::EMAIL, 'password' => self::PASSWORD];
        try
        {
            $this->response = $this->client->post($url, ['query' => $data]);
            $json = json_decode($this->response->getBody()->getContents());
            $this->accessToken = $json->access_token;
        }
        catch (RequestException $e)
        {
            $this->response = $this->StatusCodeHandling($e);
        }
    }

It works for me in curl when I put in the credentials, but I'm not sure if it will work the same in this code. Here is the curl:

curl -H "Content-Type: application/json" \
  -X POST \
  -d '{"email":"[email protected]","password":"secret"}' \
  https://someapiurl/signin

Would you mind looking at it and letting me know if it's correct or if I did something worng, thank you.

Feb
10
4 months ago
Activity icon

Replied to Composer Global Require Enlightn/security-checker - Laravel/installer V3.1.0 Requires Php ^7.2.9 -> Your Php Version (8.0.2) Does Not Satisfy That Requirement.

that fixed it, thanks.

laravel -v
Laravel Installer 4.1.1
- Installing enlightn/security-checker (v1.5.0): Extracting archive
Activity icon

Started a new Conversation Composer Global Require Enlightn/security-checker - Laravel/installer V3.1.0 Requires Php ^7.2.9 -> Your Php Version (8.0.2) Does Not Satisfy That Requirement.

I'm trying to install the new security-checker to help keep my project up to date. When I run the command composer global require enlightn/security-checker I get this error:

Using version ^1.5 for enlightn/security-checker
./composer.json has been updated
Running composer update enlightn/security-checker
Loading composer repositories with package information
Updating dependencies
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - laravel/installer is locked to version v3.1.0 and an update of this package was not requested.
    - laravel/installer v3.1.0 requires php ^7.2.9 -> your php version (8.0.2) does not satisfy that requirement.


Installation failed, reverting ./composer.json and ./composer.lock to their original content.

PHP version 8

php -v
PHP 8.0.2 (cli) (built: Feb  7 2021 12:22:16) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.2, Copyright (c) Zend Technologies
    with Zend OPcache v8.0.2, Copyright (c), by Zend Technologies

composer version

composer --version
Composer version 2.0.8 2020-12-03 17:20:38

laravel version

 laravel -v
Laravel Installer 3.1.0

my composer.json file has this in it

"require": {
        "php": "^7.2.5 || ^8.0",

What should I do to fix this problem?

Jan
15
4 months ago
Activity icon

Awarded Best Reply on Eloquent Restore SoftDeletes

Found the solution. It's easier than I thought.

Just have to add ->withTrashed() in the model.

in my case the model was this:

class Service extends Model
{
    use SoftDeletes;
    protected $guarded = [];

    public function invoice()
    {
        return $this->belongsTo(Invoice::class)->withTrashed();
    }
}

I changed it to this:

public function invoice()
    {
        return $this->belongsTo(Invoice::class)->withTrashed();
    }

I did the same in my customer model too and now everything is working fine. Source is here: https://laraveldaily.com/belongsto-and-withtrashed-linking-to-deleted-row/

Activity icon

Replied to Eloquent Restore SoftDeletes

Found the solution. It's easier than I thought.

Just have to add ->withTrashed() in the model.

in my case the model was this:

class Service extends Model
{
    use SoftDeletes;
    protected $guarded = [];

    public function invoice()
    {
        return $this->belongsTo(Invoice::class)->withTrashed();
    }
}

I changed it to this:

public function invoice()
    {
        return $this->belongsTo(Invoice::class)->withTrashed();
    }

I did the same in my customer model too and now everything is working fine. Source is here: https://laraveldaily.com/belongsto-and-withtrashed-linking-to-deleted-row/

Jan
12
5 months ago
Activity icon

Replied to Eloquent Restore SoftDeletes

What do you mean? Service doesn't have a direct relationship to Customer, it's going through Invoice. Is there a way to make a relationship with Customer from Service?

Activity icon

Replied to Eloquent Restore SoftDeletes

Kind of, but I'm getting this error when I try that. I guess because customer is not deleted and the other two are, i'm not sure.

Illuminate\Database\Eloquent\RelationNotFoundException
Call to undefined relationship [customer] on model [App\Service]. 

basically what I'm trying to do is this query which will give me the results I need.

SELECT *
FROM   services,
       invoices,
       customers
WHERE  services.invoice_id = invoices.id
       AND services.deleted_at IS NOT NULL
       AND invoices.deleted_at IS NOT NULL
       AND invoices.customer_id = customers.id
       AND customers.deleted_at IS NULL;

I just don't know how to do it with eloquent or if it's even possible. I would like it if eloquent would automagically know that invoice and service was deleted, but not customer and return all of that as a collection. That way I can just do a foreach and print out all the data, but right now it's returning null.

Jan
11
5 months ago
Activity icon

Started a new Conversation Eloquent Restore SoftDeletes

I'm using SoftDeletes in my models. My models are Customer->Invoice->Service and they have a hasMany relationship. $Customer->hasMany(Invoice::Class), $Invoice->hasMany(Service::class) and like wise $Service->belongsTo(Invoice::class), $Invoice->belongsTo(Customer::class). I'm trying to allow the user to do SoftDeletes on any one of these models. For Example if they delete an Invoice it will also delete all Service attached to that Invoice and the same goes for Customer which will delete all Invoice and Service. Since I'm doing SoftDeletes I want to display only the deleted stuff for them so they can restore it. All the deleting works, but I'm having problems displaying something if an Invoice gets deleted.

I'm getting this error

ErrorException Trying to get property 'customer' of non-object

This is my function in my ServiceController that returns the view

public function restore()
    {
        $services = Service::onlyTrashed()->paginate(5);
        return view('services.restore', compact('services'));
    }

This is my view where I get the error:

@foreach($services as $service)
	<form action="{{route('services.restore', ['id' => $service->id])}}" method="POST">
	@method('PATCH')
	@csrf
	<div class="card mb-2" style="width: 18rem;">
		<div class="card-body">
			<h5 class="card-title">
			{{--non-object error--}}
			{{$service->invoice->customer->name}}
			</h5>
			<h6 class="card-subtitle mb-2 text-muted">
			Service : {{$service->id}}
			</h6>
			<button class="btn btn-success btn-sm" type="submit">Restore</button>
		</div>
	</div>
</form>
@endforeach

Is there a way to do this in eloquent? Something like

$services = Service::with('invoice.customer')->onlyTrashed()->paginate(5);

This wouldn't really fit since I might have a customer that wasn't trashed, but you get the idea. How would you do this? Should I make my own scope instead?

Jan
10
5 months ago
Activity icon

Replied to How To Fix Bad Registration For Vue Warning Message

Thank you, didn't see that. What about registration global vs local? Any idea which is better? Some online sources suggest it's better to use local over global. What are your thoughts on this? And thanks again!

Activity icon

Started a new Conversation How To Handle Soft Deletes With Daisy Chained Tables/models?

I can handle this with some logic in php, but I was wondering if there is something already built into Eloquent for this type of situation. I have 3 tables with a $this->hasMany type of relation. Lets say I want to delete something from table 2. Is there a feature in eloquent that lets you do a soft delete only if there's no fk referencing the entry in another table? For example User->Invoice->Order I would like to do a soft deletes on an invoice, but I need to make sure it has no orders attached to it. Also is there way to do cascade delete in eloquent (like a method) so I can delete an invoice with all of it's orders or a customer with all invoices and orders ?

Activity icon

Started a new Conversation How To Fix Bad Registration For Vue Warning Message

I started following some tutorials for Vue and I'm getting this warning message

[Vue warn]: Unknown custom element: <lable> - did you register the component correctly?

Here is my resources/js/component/flashMessage.vue

<style>
    .fade-enter-active, .fade-leave-active {
        transition: opacity 1.5s ease-out;
    }
    .fade-enter, .fade-leave-to {
        opacity: 0;
    }
</style>

<template>
    <div>
        <transition name="fade">
            <div class="alert alert-success" role="alert" v-if="show">
                <strong>Success.</strong> {{message}}
            </div>
        </transition>
    </div>
</template>

<script>
    export default {
        data(){
            return {
                show : true,
            }
        },
        mounted() {
            setTimeout(() => {this.show = false;}, 2500);
            console.log('Component mounted.')
        },
        props : ['message'],

    }
</script>

Here is my app.js

Vue.component('flash-message', require('./components/flashMessage.vue').default);

My understanding is that this is a global registration of the component so I shouldn't be seeing this warning message in the console. Would someone please explain to me what I'm getting wrong here? Thank you in advance!

edit: Also, what would be best practice in this situation. Using a global registration or local?

Jan
08
5 months ago
Activity icon

Started a new Conversation Classic 404, Kind Of Solved It. What's Wrong With This?

I'm trying to make a view that will display things that were soft deleted inside the same controller called ServicesController. I made a Route for it as you can see below and when I would click on the link I would get a 404. The links are inside of a form with method="GET" and work if I remove my show route. I don't understand why it works when I remove the show Route, but gives me a 404 when I put it back in. I don't actually have a link for the user to click on to visit the show view and if I type it in manually I get a 404 which is fine since I'm not doing anything with it yet.

Here's my web.php

//Services
Route::get('services', '[email protected]')->name('services.index');
Route::get('services/create', '[email protected]')->name('services.create');
Route::post('services','[email protected]')->name('services.store');
//the show function below doesn't actually do anything, but when I remove it the routing works for services/deleted
Route::get('services/{service}', '[email protected]')->name('services.show');
Route::get('services/{service}/edit', '[email protected]')->name('services.edit');
Route::patch('services/{service}','[email protected]')->name('services.update');
Route::delete('services/{service}', '[email protected]')->name('services.destroy');
Route::get('services/deleted', '[email protected]')->name('services.deleted');

Here are my links

    <ul class="nav nav-tabs flex-column">
        <li class="nav-item pb-2">
            <a class="nav btn-outline-primary text-left nav-link {{ (request()->is('add')) ? 'active' : '' }}"
               href="{{route('services.create')}}" name="add" id="add">Add Service</a>
        </li>
        <li class="nav-item pb-2">
            <a class="nav btn-outline-primary text-left nav-link {{ (request()->is('deleted')) ? 'active' : '' }}"
               name="deleted" id="deleted" href="{{route('services.deleted')}}">Restore Service</a>
        </li>
    </ul>

Here is my show function, there's no actual link to it. If I try navigating to it in the url localhost/services/show I also get a 404 which is to be expected

    public function show(Service $service)
    {
        $invoice = Invoice::where('id',$service->invoice_id)->firstOrFail();
        $customer = Customer::where('id',$invoice->customer_id)->firstOrFail();

        return view('services.show', compact('invoice','service','customer'));
    }

Here is my deleted function

    public function deleted()
    {
        $services = Service::onlyTrashed()->paginate(25);
        return view('services.deleted', compact('services'));
    }

Conclusion. I don't get how or why the show route is messing things up for me, but removing it solves the problem. I'm hoping someone could explain this to me. I would like to know are controllers limited to the number of functions that can be routed by default in laravel? What am I missing here? Please let me know, thank you.

Dec
28
5 months ago
Activity icon

Replied to Using A Destroy Function Inside Of An Index View

I'm still learning javascript. I was hoping to stick with html/php, but your idea would make things easier in the long run, thank you.

Activity icon

Replied to Using A Destroy Function Inside Of An Index View

I was using it before for something else, but now that I don't need it I'll get rid of that, thanks.

Activity icon

Started a new Conversation Using A Destroy Function Inside Of An Index View

I have this bit of code that's basically generating a list and I want to have an edit link and a delete button in that list. Here is the code with just the edit link.

<form action="{{route('services.index')}}" method="GET" class="pb-15" autocomplete="off">
                    <ol>
                    @if($customers ?? '')
                        @foreach($customers as $customer)
                            @foreach($customer->invoices as $invoice)
                                    @foreach($invoice->services as $service)
                                        <li value="{{$service->id}}">
					 {{$customer->internal_name}} 
					<a href="{{route('services.edit', 
					['service' => $service])}}">edit</a></li>
                                    @endforeach
                                @endforeach
                            @endforeach
                    @endif
                    </ol>
                </form>

I would like to add a delete button there, but I'm not sure how to do it without making everything look ugly.

Here's what I tried:

<form action="{{route('services.index')}}" method="GET" class="pb-15" autocomplete="off">
                    <ol>
                    @if($customers ?? '')
                        @foreach($customers as $customer)
                            @foreach($customer->invoices as $invoice)
                                    @foreach($invoice->services as $service)
                                        <li value="{{$service->id}}">
					 {{$customer->internal_name}} 
					<a href="{{route('services.edit', 
					['service' => $service])}}">edit</a>
	<form action="services/{{$service->id}}" method="POST">
                                            @method('DELETE')
                                            @csrf
                                            <button class="btn-danger" type="submit">Delete</button>
</form></li>
                                    @endforeach
                                @endforeach
                            @endforeach
                    @endif
                    </ol>
                </form>

It works, but it looks really bad on the ui side of things because the button isn't exactly on the same level as the rest of the information since it's in another form. Does anyone have an idea how I can do this and make it look nice in the list?

Dec
20
5 months ago
Activity icon

Replied to Doesn't Display Text For User In Textarea Value="{{old(value) ?? $data->someData}}"

thank you, didn't know that "Default content entered between the opening and closing tags. does not support the value attribute."

Activity icon

Started a new Conversation Doesn't Display Text For User In Textarea Value="{{old(value) ?? $data->someData}}"

I have this line of code

<textarea name="description" id="description" cols="30" rows="10" class="form-control" value="{{old('description') ?? $service->description}}"></textarea>

it should display either old value or what's in the db, but it doesn't show up in the text area for the user to see. When I check in dev tools inside the browser I see that value="my data here", but for some reason it doesn't display it for the user to see.

I tried this instead

<textarea name="description" id="description" cols="30" rows="10" class="form-control" value="">{{old('description') ?? $service->description}}</textarea>

this will display the data for the user, but it doesn't store it in value=""

any help would be appreciated. I'm not sure what I'm doing wrong here.