DrewRoberts

Experience

26,000

0 Best Reply Awards

  • Member Since 1 Year Ago
  • 256 Lessons Completed
  • 2 Favorites

28th May, 2017

DrewRoberts left a reply on Issue With Multiple Route Parameters • 1 year ago

Thanks, Snapey. That worked. Here's what I used in my QuotesController.php file:


    /**
     * Display the specified resource.
     *
    * @param  $authorId
     * @param  \App\Quote  $quote
     * @return \Illuminate\Http\Response
     */
    public function show($quoteauthor, Quote $quote)
    {
        if ($quoteauthor !== $quote->author->slug) {
            return redirect()->to($quote->path());
        }

        return view('quotes.quotations.show', compact('quote'));
    }

DrewRoberts started a new conversation Issue With Multiple Route Parameters • 1 year ago

I am working on a route that looks like:


Route::get('quotes/{quoteauthor}/{quote}', '[email protected]');

It works, but it has an issue: When I visit any quote id, it will make the page appear behind an incorrect quote author. I notice the same issue here with the discussions on Laracasts:

Both of those show the same page, but one is an incorrect URL putting this discussion behind a channel where it does not exist. Is there a way to limit the second parameter to only show those items that have a relationship with the first model? How would I redirect the URL to the correct parameter on the first model?

DrewRoberts left a reply on Best Practice For HTTP Redirect • 1 year ago

@martinbean, I'm making a change to my route structure:

Route::get('quotes/{quoteauthor}/{quote}', '[email protected]')->name('quote.show');

What changes do I need to make to the redirect route to have it pull the correct author for the quote and redirect it the appropriate URL?

26th May, 2017

DrewRoberts left a reply on Best Practice For HTTP Redirect • 1 year ago

That's beautiful, @martinbean. It worked like a charm.

DrewRoberts started a new conversation Best Practice For HTTP Redirect • 1 year ago

I'm reading the documentation on redirects (https://laravel.com/docs/5.4/redirects), but having some trouble setting one up the way I want. I have a quotes database table with an id column that begins incrementing at 1,000,000 so there will always be 7 digit id numbers for them. I want people to visit mywebsite.com/1000000 and be redirected to mywebsite.com/quotes/quotations/1000000 and have tried the following to avail:

''' Route::get('quotes/quotations/{quote}', '[email protected]');

Route::get('{quote}', function () { return redirect()->action( '[email protected]', ['id' => {quote}] ); '''

I have also tried things like:

''' Route::get('quotes/quotations/{quote}', '[email protected]');

Route::get('{quote}', function () { return redirect('quotes/quotations/{quote}', '[email protected]'); }); '''

My main route works, but both attempts at the redirect are failing. I think it is not passing along the prior {quote} id value, but I can't find an example with this to fix it. Any help and advice on the best practice for implementing this would be appreciated. Thanks

24th May, 2017

DrewRoberts left a reply on Custom Key Name With Field From Different Table • 1 year ago

Thank you both for the insight. I agree that it would be better to use book_authors as a pivot table between authors and books and also another table for contributions. That table would essentially key if the author was a solo author for the book, a co-author, editor, contributor, etc.

The authors table however will have more than just authors who wrote books. It will also include authors of articles and other content. I have an App/Author model that displays them in another section, but I would like to display just the Authors who have written books in this books section of the website with a different view. It seems the best way to accomplish this would be to have this model also use the authors table and just restrict the authors using a where clause for those included in the pivot table. I think Jeffrey has some videos explaining the best way to do this.

DrewRoberts left a reply on Custom Key Name With Field From Different Table • 1 year ago

Thank you, Tekmi. I thought that might be the case since I couldn't find anything on this. If I used the authors table and used a where clause to limit it to only authors that had a matching id in the book_authors table, what would be the best way to approach that?

DrewRoberts started a new conversation Custom Key Name With Field From Different Table • 1 year ago

I have two database tables that I want to use in my model with the main one being a subset of authors, those with published books. The model should only include authors that are in this table but I want to use a custom Key Name for the model of the slug that is associated with the author in the larger authors table. I can't find anything on how to accomplish this and would appreciate your help. Here's what I have so far in App/BookAuthor:

class BookAuthor extends Model { public $table = "book_authors"; public $table = "authors";

/**
 * Get the route key for the model.
 *
 * @return string
 */
public function getRouteKeyName()
{
    return 'slug'; //This field is only in the authors table
}

15th May, 2017

DrewRoberts started a new conversation Laracasts User Profile URL Structure (/@Username) • 1 year ago

What's the best practice for setting up user profiles with a URL structure of /@Username like that used here on Laracasts or on Medium? In Laravel, what would I insert in the route file?

On a side note, what are the SEO implications of using the @ sign in a URL? Are there any negative consequences for search engine readability?

Edit Your Profile
Update

Want to change your profile photo? We pull from gravatar.com.