HomeController ve TagsController dosyalarımı paylaşacağım. Card tagleri slug olarak gelirken card başlıkları (site linkleri) slug olarak gelmiyor sorunum bu. RESİMLERLE GÖSTERİCEM.
Slug olarak gelen TAGLER
Slug olarak gelmeyen Card title = site linki
HomeController.php
public function store(Request $request)
{
if(Settings::find('active_upload')->value == 0){
toastr()->warning(__('main.new_entries_paused'));
return redirect('/');
}
Validator::make($request->all(), [
'title' => 'required|string|max:255',
'story' => 'required|string|min:'.Settings::find('minimum_characters')->value.'|max:'.Settings::find('maximum_characters')->value,
'tags' => 'nullable',
'category_id' => 'required',
'genders_id' => 'required',
'age' => 'required',
'photo' => 'nullable|image|mimes:jpeg,png,jpg|max:2048'
],[
'title.required' => 'Bir Başlık Giriniz.',
'title.max' => 'Başlık 255 Karakterden Uzun Olamaz.',
'story.required' => 'Boş bırakılmamalıdır.',
'story.min' => 'Girilen Metin '.Settings::find('minimum_characters')->value.' Karakterden Fazla Olmalıdır.',
'story.max' => 'Girilen Metin ' .Settings::find('maximum_characters')->value.' Karakterden Az Olmalıdır.',
'category_id.required' => 'Kategori Seçmeniz Gerekiyor.',
'photo.image' => 'Lütfen Resim Dosyası Yükleyiniz.',
'photo.mimes' => 'Dosya Biçimi jpg,png veya jpeg olmalıdır.',
])->validateWithBag('write');
// if word censored is active
if(Settings::find('words_censored')->value == 1) {
$censor = new CensorWords;
$badwords = $censor->setDictionary(base_path('/vendor/snipe/banbuilder/src/dict/dictionary.php'));
$string = $censor->censorString($request->story)['clean'];
} else {
$string = $request->story;
}
//
// create item
$create_item = Items::create([
'title' => $request->title,
'story' => $string,
'slug' => $this->make_slug($request->title),
'status' => Settings::find('new_entries')->value,
'user_id' => Auth::id(),
'category_id' => $request->category_id,
'genders_id' => $request->genders_id,
'age' => $request->age,
]);
if ($create_item) {
// if exists, upload photo
if ($request->hasFile('photo')) {
// upload original
$path = $request->file('photo')->store('photos');
// store photo
$storePhoto = Photos::create([
'item_id' => $create_item->id,
'filename' => $path
]);
}
// create tags
$tags = explode(",", $request->tags);
$create_item->tag($tags);
if(Settings::find('status_points')->value == 1){
if(Settings::find('status_points_new_entry')->value == 1){
Points::create([
'user_id' => Auth::id(),
'point_type' => "new_entry",
'score' => Settings::find('points_new_entry')->value,
'item_id' => $create_item->id
]);
}
}
if(Settings::find('new_entries')->value == 1){
toastr()->success(__('main.toast_your_post_has_been_posted'));
return redirect('/');
} else {
toastr()->warning(__('main.toast_post_in_moderation'));
return redirect('/');
}
} else {
toastr()->error(__('main.toast_there_are_problems_try_again'));
return redirect('/')->withErrors($validator, 'write')->withInput();
}
}
TagsController.php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Session;
use Illuminate\Http\RedirectResponse;
use Illuminate\Support\Str;
use Illuminate\Database\Eloquent\Builder;
use App\Models\Settings;
use App\Models\User;
use App\Models\Items;
use App\Models\Categories;
use App\Models\Pages;
class TagsController extends Controller
{
public function __construct()
{
$this->categories = Categories::where('status', 1)->get();
$this->pages = Pages::where('status', 1)->get();
$this->results_per_page = Settings::find('results_per_page')->value;
}
// ***
// fetch items with this tag
// ***
public function tag($slug)
{
// get items list
$items = Items::whereHas('category', function ($query) {
if(Auth::check()){
$userPoints = Auth::user()->total_point_count(); // if you are logged in, assign points to the current user
} else {
$userPoints = 0; // if he is a guest he awards 0 points
}
$query->where('score', '<=', $userPoints);
$query->where('status', 1);
})->withAnyTag([$slug])
->where('status', 1)
->orderByDesc('featured')
->orderByDesc('id')
->paginate($this->results_per_page);
return view('layouts.tags.index')->with([
'site_name' => Settings::find('site_name')->value,
'site_description' => Settings::find('site_description')->value,
'page_name' => $slug,
'categories' => $this->categories,
'pages' => $this->pages,
'status_write' => Settings::find('active_upload')->value,
'story_preview_chars' => Settings::find('story_preview_chars')->value,
'items' => $items,
'tag' => $slug
]);
}
}