web.php
1 2 3 |
Route::resources([ 'admin/kategori' => 'backend\kategori', ]); |
controller içinde yer alan backend klasörü kategori controllerına admin/kategori linkine gidecek şekilde yaptık.
category modeli oluşturduk.
1 2 3 4 5 |
class Category extends Model { protected $table = 'category'; protected $primaryKey ='category_id'; } |
Kategori controller’i;
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
public function index() { $cat = Category::where('tip_id',1)->get(); $makale = Category::where('tip_id',2)->get(); $hesapkit = Category ::where('tip_id',3)->get(); return view('backend.kategori.kategori_list')->with('cat',$cat)->with('makale',$makale)->with('hesapkit',$hesapkit); } /** * Show the form for creating a new resource. * * @return \Illuminate\Http\Response */ public function create() { return view('backend.kategori.kategori_create'); } /** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { $validatedData = $request->validate([ 'category_name' => 'required|max:255', 'tip_id' => 'required' ]); $category = new Category(); $category->category_name = $request->category_name; $category->tip_id = $request->tip_id; $category->slug = str_slug($request->category_name); $category->save(); return redirect()->route('kategori.index')->with('success','Başarıyla Kaydedildi.'); } /** * Display the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function show($id) { // } /** * Show the form for editing the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function edit($id) { return view('backend.kategori.kategori_edit')->with('data',Category::find($id)); } /** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(Request $request, $id) { $validatedData = $request->validate([ 'category_name' => 'required|max:255', 'tip_id' => 'required' ]); $category = Category::find($id); $category->category_name = $request->category_name; $category->tip_id = $request->tip_id; $category->slug = str_slug($request->category_name); $category->save(); return redirect()->route('kategori.index')->with('success','Güncelleme işlemi başarıyla kaydedildi.'); } /** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy($id) { Category::find($id)->delete(); return redirect()->route('kategori.index')->with('success','Başarıyla silindi.'); } |
kategori_create.blade.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
<form action="{{ route('kategori.store') }}" method="POST"> @csrf <div class="form-group"> <label for="exampleInputEmail1">Kategori İsmi</label> <input type="text" class="form-control {{ $errors->has('category_name') ? ' is-invalid' : '' }}" name="category_name" placeholder="Kategori İsmini Giriniz"> <small id="emailHelp" class="form-text text-muted">Boş Bırakmayınız</small> @if ($errors->has('category_name')) <span class="invalid-feedback" role="alert"> <strong>{{ $errors->first('category_name') }}</strong> </span> @endif </div> <div class="form-group"> <label for="exampleInputPassword1">Ana Kategori Seçiniz</label> <select name="tip_id" class="form-control"> <option value="1">Haber</option> <option value="2">Makale</option> <option value="3">Hesap Kiti</option> </select> </div> <div class="form-group"> <button type="submit" class="btn btn-primary btn-lg btn-block">Gönder</button> </div> </form> |
kategori_edit.blade.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
<form action="{{route('kategori.update',['id' => $data->category_id])}}" method="POST"> @csrf {{ method_field('PATCH') }} <div class="form-group"> <label for="exampleInputEmail1">Kategori İsmi</label> <input type="text" class="form-control {{ $errors->has('category_name') ? ' is-invalid' : '' }}" name="category_name" value="{{$data->category_name}}"> <small id="emailHelp" class="form-text text-muted">Boş Bırakmayınız</small> @if ($errors->has('category_name')) <span class="invalid-feedback" role="alert"> <strong>{{ $errors->first('category_name') }}</strong> </span> @endif </div> <div class="form-group"> <label for="exampleInputPassword1">Ana Kategori Seçiniz</label> <select name="tip_id" class="form-control"> <option value="1" @if($data->tip_id==1) selected @endif>Haber</option> <option value="2" @if($data->tip_id==2) selected @endif>Makale</option> <option value="3" @if($data->tip_id==3) selected @endif>Hesap Kiti</option> </select> </div> <div class="form-group"> <button type="submit" class="btn btn-primary btn-lg btn-block">Gönder</button> </div> </form> |
kategori_list.blade.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
@if ($message = Session::get('success')) <div class="alert alert-success"> {{ $message }} </div> @endif <h4>xx Kategorileri</h4> <table class="table table-hover"> <thead> <tr> <th>#</th> <th>İsim</th> <th>Slug Yapısı</th> <th>Oluşturulma Tarihi</th> <th>İşlemler</th> </tr> @foreach($hesapkit as $h) <tr> <th>{{ $h->category_id}}</th> <th>{{ $h->category_name }}</th> <th>{{ $h->slug }}</th> <th>{{ date_format($h->created_at,'d.m.Y H:i:s') }}</th> <th> <a href="{{ url('admin/kategori/create') }}"><i class="i-rounded i-small icon-line2-magnifier-add"></i></a> <a href="{{ url("admin/kategori/".$h->category_id."/edit") }}"><i class="i-rounded i-small icon-edit"></i></a> <a href="javascript:void(0);" onclick="$(this).find('form').submit();" > <i class="i-rounded i-small icon-remove"></i> <form action="{{ URL::route('kategori.destroy', $h->category_id) }}" method="post"> <input type="hidden" name="_method" value="DELETE"> @csrf </form> </a> </th> </tr> @endforeach </thead> </table> |