mdavis1982's avatar

A Few Ideas

I have a few ideas for Laracasts videos that I would like to see covered:

  • Generating slugs for models without using a dedicated package
  • Adding a related model at the same time as creating a model (e.g., creating tags at the same time as creating a post)
  • Embedded forms (imagine having a Product model and form - how would you add multiple YouTubeVideo models with embedded forms when creating a new Product with little + and - buttons to dynamically add a new form row)
  • Multiple image uploads (e.g. uploading multiple images for a Product when creating one)

I think these would be great videos and things that we all do every day so it would be nice to see them covered along with the other aspects of managing them (like editing etc).

0 likes
3 replies
dberry's avatar

Slugs can be handled pretty easily, just use a mutator:

public function setMySlugAttribute($value) 
{
    $this->attributes['my_slug']  = \Str::sluggable($value) ;
} 

If you want, you can throw in validation or whatever, or use a different field, whatever you want. You can throw it in a trait to reuse.

I've never used a package to handle slugs.

Adding a related model is also pretty trivial and there is an example in the docs.

For dynamically adding rows, that is pretty trivial as well and is javascript. Google "jquery add remove rows"

Multiple video uploads, just do a foreach and loop over them.

mdavis1982's avatar

Thanks for your reply.

It's certainly easy to do slugs, but there are lots of cases to cover - do you want them to update when you update the model etc? It's trivial - I just think it would be good to cover it here.

Related models and stuff do have examples in the docs - but not using Form Requests and with validation etc! Dynamically adding the form rows and removing them is trivially easy with JS - I've done it many times - I've just never handled it in Laravel once it's been submitted.

I think that these things are things that we do every day, and I'd like to see examples of doing them here at Laracasts because I think it would help newcomers to be able to see examples of lots of common things :)

jekinney's avatar

Good points, and those questions come up a lot not only here.

One comment: Keep in mind there really is no laravel way, while I understand the statement because laravel has a lot of helpers like the slug at the end of the day, it is all PHP.

Adding many YouTube links is looping through an input array. It cloud be empty, one link, or a dozen.

Though I totally agree there are so many basics that don't get covered. Seems roles and permissions are arguably the number one question here yet minimal videos on it.

Please or to participate in this conversation.