chrispage1

chrispage1

Member Since 1 Year Ago

Experience Points 21,790
Experience Level 5

3,210 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 213
Lessons
Completed
Best Reply Awards 0
Best Reply
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.

18 Apr
1 day ago

chrispage1 left a reply on Attaching Many To Many Relations While Still Binding To Created Event

So I posted this question on Stackoverflow too and got a really useful answer. There's a transactional events package (https://github.com/fntneves/laravel-transactional-events) which allows you to wrap code in Database Transactions, and only once the transaction completes will the event get fired.

So having this installed and applying the TransactionalEvent contract to my OrderCreated event gives me the desired effect.

I can then emit OrderCreated within my Order observer and as long as the order creation was performed within a transaction that includes the product assignment it works great. Example -

\DB::transaction (function () use ($request) {
    $order = Order::create($request->validated());
    $order->products()>attach([1,2,3,...]);
});

chrispage1 left a reply on Attaching Many To Many Relations While Still Binding To Created Event

@MKBAT - Thanks for your input. This would still fire the created event before the products get attached. Looks like I'll just have to fire my own event. Thanks though!

chrispage1 left a reply on Attaching Many To Many Relations While Still Binding To Created Event

@SNAPEY - Sure - that's what I thought and what I'm currently doing. Was just seeing if there was something I was missing and an alternate way of establishing many to many relations during creation.

Seems not! Thanks for your feedback

17 Apr
2 days ago

chrispage1 started a new conversation Attaching Many To Many Relations While Still Binding To Created Event

So I've run into this issue a few times and now I've decided that I want to find a better solution.

I have two models, Order & Product. There is a many to many relation so that an order can have multiple products. Table structure looks like the below -

orders

  • id
  • more fields...

products

  • id
  • more_fields...

product_orders

  • order_id
  • product_id

So when an order is created I run the following -

$order = Order::create($request->validated())

$order->products()->attach([1,2,3,4...]);

So this does what I want and creates an order record with attached products. However, I want to bind to the Order Created event and get all the linked products in any listeners that may be bound. Problem being, at the time the order created event is fired, the products aren't yet attached. Is there any way to do the above, establishing all the relationships and creating the order at the same time so I can access linked products within the Order Created event listeners?

Thanks, Chris.

29 Mar
3 weeks ago

chrispage1 left a reply on How To Add Search Functionality In A Table In Laravel

@KISAW88 - Search form in blade can be -

<form method="POST" action="/users">
    @csrf
    <input type="search" placeholder="Search here" />
    <button type="submit">Search</button>
</form>

Then on your controller method you do the following (with a Scout plugin installed) - 

if ($request->has('search')) { $users = User::search($request->input('search')); } else { $users = User::query(); }

return view('users', ['users' => $users->paginate()]);

28 Mar
3 weeks ago

chrispage1 left a reply on How To Add Search Functionality In A Table In Laravel

I'd recommend using a plugin. Take a look at Laravel TNTSearch, it's a driver for Laravel Scout and brilliant - https://github.com/teamtnt/laravel-scout-tntsearch-driver

22 Mar
4 weeks ago

chrispage1 left a reply on Add Fulltext Index Within Migration Schema

Just for anyone who stumbles upon this and my own reference in future - I ended up using Laravel Scout TNTSearch package (https://packagist.org/packages/teamtnt/laravel-scout-tntsearch-driver)

It's been perfect for my requirements

20 Feb
1 month ago

chrispage1 started a new conversation Standard Auth Package Emails Not Rendering Properly

Hi,

I've setup Laravel Authentication using php artisan make:auth. Everything worked great other than my reset emails half render as if they are being processed via Markdown. I haven't customised any of the mailables, password broker, controllers etc, everything is stock - I can't work out why this would be happening?

See this image - https://imgur.com/qUR45Ed

I hope someone can help!

26 Jan
2 months ago

chrispage1 left a reply on Using Factories To Seed Sub-relations

Ah - I need those there because its a multi tenancy system. Once client can have many asset types which in turn has many assets. Originally I didn't have the client_id column on the assets table but then decided for the sake of transparency and ease of querying, logic etc etc I would just have it on all three tables.

Right - all my tests are now working with SQLite which was this evenings aim. Thank you! :)

chrispage1 left a reply on Using Factories To Seed Sub-relations

I've been overlooking a really obvious solution... What about doing this - any objections?

$factory->define(Asset::class, function (Faker $faker, array $args = []) {

    $client_id = isset($args['client_id'])
        ? $args['client_id']
        : factory(Client::class)->create();

    return [
        'client_id' => $client_id,
        'asset_type_id' => factory(AssetType::class)->create(['client_id' => $client_id]),
        'asset_model_id' => factory(AssetModel::class)->create(['client_id' => $client_id]),
        'name' => $faker->word,
    ];
});

chrispage1 left a reply on Using Factories To Seed Sub-relations

@ANDYLORD565 - Thanks Andy - for the sake of speed I was hoping I could do something within the factory so that when I spin up an Asset it automatically took care of the Asset Type & Asset Model creation so all I had to type was factory(App\Asset::class)->create() in my tests.

Appreciate your feedback and pointers :)

chrispage1 started a new conversation Using Factories To Seed Sub-relations

I've been watching lots of tutorials and I want to get better at writing tests for my integrations. I've created factories but I'm a little stuck at this point on how to seed the database with all the relevant data...

On my system I have three tables, assets, asset_types & asset_models. Each of these belong to a client master record.

assets

  • id
  • client_id
  • asset_type_id
  • asset_model_id
  • name
  • year...

asset_types

  • id
  • client_id
  • name

asset_models

  • id
  • client_id
  • name

So my question is, how could I reliably seed this so that Asset model generates a client, and asset_types & asset_models generate the client? Currently I've got the following -

$factory->define(Asset::class, function (Faker $faker) {

    return [
        'client_id' => factory(Client::class),
        'asset_type_id' => factory(AssetType::class),
        'asset_model_id' => factory(AssetModel::class),
        'name' => $faker->word,
    ];
});

The problem is that by using factory(AssetType::class), it can actually generate an asset type with a completely different client id to the parent asset?

I hope this makes sense and someone can help!

Thanks, Chris.

02 Sep
7 months ago

chrispage1 started a new conversation Add Fulltext Index Within Migration Schema

Hi,

I'm creating a plugin where I'm making a migration method. Within the method, I'd like to add a FULLTEXT index -

public function migrateUp(Blueprint $table, $after = null)
{

    // add our searchable column
    $table
        ->longText($this->_searchableColumnKey)
        ->after($after)->nullable();

    // add a fulltext index
    DB::statement(
        'ALTER TABLE ? ADD FULLTEXT fulltext_searchable (?)',
        [$table->getTable(), $this->_searchableColumnKey]
    );

    // return our table
    return $table;
}

However, at the point DB::statement() gets run, our column doesn't yet exist. Is there a callback on the longText that I could run?

Cheers!

29 Jun
9 months ago

chrispage1 started a new conversation Using Jobs To Check Video Transcoding Status

Hi,

I'm sending videos to Amazon Elastic Transcoding service. I've currently setup a job for creating the task in Amazon (StartVideoTranscode.php), and a second job (CheckVideoTranscode.php) for monitoring the status of the task.

Currently, the second task, CheckVideoTranscode, goes to Amazon, checks the status of the job and if its still in Progress fires the CheckVideoTranscode job again with the same parameters after a delay of 30 seconds.

I'm fairly new to Laravel & Laravel jobs so wanted to see if this would be the right way to do things. For some reason this just doesn't feel right to me?

Chris.