0

Currently, I am using spatie/laravel-translatable package and for slug cviebrock/eloquent-sluggable, but when I want to go specific post I mean when clicking "read more" button of post it is going to page not found. Here is my code:

Route:

Route::group(['prefix' => '{locale}', 'where' => ['locale' => '[a-zA-Z]{2}'], 'middleware'=>'setLocale'], function() {
    Route::get('/news-events', 'FrontController@newsEvents')->name('news_events');
    Route::get('/news-events/{id}', 'FrontController@newsSingle')->name('news-single');
});

Model:

<?php

namespace App;

use Cviebrock\EloquentSluggable\Sluggable;
use Cviebrock\EloquentSluggable\Services\SlugService;
use Illuminate\Database\Eloquent\Model;
use Spatie\Translatable\HasTranslations;
use Cviebrock\EloquentSluggable\SluggableScopeHelpers;

class NewsPost extends Model
{
    use HasTranslations;
    use SluggableScopeHelpers;
    use Sluggable;
    protected $translatable = [
        'title',
        'title_ar',
        'description',
        'description_ar'
    ];
    protected $fillable = [
        'is_publish',
        'title',
        'description',
        'cat_id',
        'media_id'
    ];
    protected $sluggable = array(
        'build_from' => 'title',
        'save_to'    => 'slug',
    );

    /**
     * Return the sluggable configuration array for this model.
     *
     * @return array
     */
    public function sluggable()
    {
        return [
            'slug' => [
                'source' => 'title'
            ]
        ];
    }

    public function category(){
        return $this->belongsTo('App\NewsCategory', 'cat_id');
    }

    public function media(){
        return $this->belongsTo('App\NewsMedia','media_id');
    }
}

Front Page:

<div class="post-prev-more">
<a href="{{route('news-single', [app()->getLocale(), $news_post->slug])}}" class="btn btn-mod btn-gray btn-round">Read More <i class="fa fa-angle-right"></i>
</a>
</div>
apokryfos
  • 38,771
  • 9
  • 70
  • 114
  • Not many readers have seen this, it was missing the PHP tag. I have added it. – halfer May 13 '20 at 17:52
  • It is possible that people thought the question was not very answerable. If you have a "Read More" device then I assume you are using Ajax. If so, you can use your browser's network panel to see the URL requests going out, and see if they match the pattern you are expecting. – halfer May 13 '20 at 17:58

0 Answers0