• 16-08-2023, 16:08:46
    #1
    merhaba dün çalışan projem ne alakaysa çalışmıyor şimdi
    view dosyam
    @extends('admin.app_admin')
    @section('admin_content')
        <h1 class="h3 mb-3 text-gray-800">{{ ADD_PROPERTY_LOCATION }}</h1>
        <form action="{{ route('admin_property_location_store') }}" method="post" enctype="multipart/form-data">
            @csrf
            <div class="card shadow mb-4">
                <div class="card-header py-3">
                    <h6 class="m-0 mt-2 font-weight-bold text-primary">Yeni İlçe Ekle</h6>
                    <div class="float-right d-inline">
                        <a href="{{ route('admin_property_location_view') }}" class="btn btn-primary btn-sm"><i class="fa fa-plus"></i> {{ VIEW_ALL }}</a>
                    </div>
                </div>
                <div class="card-body">
                    <div class="form-group">
                        <label for="parent_id">Ana Kategori Seçin</label>
                        <select name="parent_id" class="form-control">
                            <option value="">Ana Kategori Seç</option>
                            @foreach ($property_locations as $location)
                                <option value="{{ $location->id }}">{{ $location->property_location_name }}</option>
                                @foreach ($all_property_locations->where('parent_id', $location->id) as $child_location)
                                    <option value="{{ $child_location->id }}">-- {{ $child_location->property_location_name }}</option>
                                @endforeach
                            @endforeach
                        </select>
                    </div>
                    <div class="form-group">
                        <label for="property_location_name">{{ NAME }} *</label>
                        <input type="text" name="property_location_name" class="form-control" value="{{ old('property_location_name') }}" autofocus>
                    </div>
                    <div class="form-group">
                        <label for="property_location_slug">{{ SLUG }}</label>
                        <input type="text" name="property_location_slug" class="form-control" value="{{ old('property_location_slug') }}">
                    </div>
                    <div class="form-group">
                        <label for="property_location_photo">{{ PHOTO }} *</label>
                        <div>
                            <input type="file" name="property_location_photo">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="page_description">{{ DESCRIPTION }} *</label>
                        <div id="editor">
                            <textarea name="page_description" class="form-control editor" value="{{old('page_description')}}"></textarea>
                        </div>
                    </div>
                </div>
                <div class="card-header py-3">
                    <h6 class="m-0 font-weight-bold text-primary">{{ SEO_INFORMATION }}</h6>
                </div>
                <div class="card-body">
                    <div class="form-group">
                        <label for="seo_title">{{ TITLE }}</label>
                        <input type="text" name="seo_title" class="form-control" value="{{ old('seo_title') }}">
                    </div>
                    <div class="form-group">
                        <label for="seo_meta_description">{{ META_DESCRIPTION }}</label>
                        <textarea name="seo_meta_description" class="form-control h_100" cols="30" rows="10">{{ old('seo_meta_description') }}</textarea>
                    </div>
                    <button type="submit" class="btn btn-success">{{ SUBMIT }}</button>
                </div>
            </div>
        </form>
    @endsection
    controller dosyam
    <?php
    namespace App\Http\Controllers\Admin;
    use App\Http\Controllers\Controller;
    use App\Models\Property;
    use App\Models\PropertyLocation;
    use Illuminate\Http\Request;
    use Illuminate\Support\Str;
    use Illuminate\Validation\Rule;
    use Illuminate\Support\Facades\Mail;
    use DB;
    use Auth;
    class PropertyLocationController extends Controller
    {
        public function __construct()
        {
            $this->middleware('auth.admin:admin');
        }
        public function index()
        {
            $property_location = PropertyLocation::orderBy('id', 'asc')->get();
            return view('admin.property_location_view', compact('property_location'));
        }
        public function create()
        {
            $property_locations = PropertyLocation::orderBy('id', 'asc')->get();
            $all_property_locations = PropertyLocation::all();
            return view('admin.property_location_create', compact('property_locations', 'all_property_locations'));
        }
        public function store(Request $request)
    {
        if (env('PROJECT_MODE') == 0) {
            return redirect()->back()->with('error', env('PROJECT_NOTIFICATION'));
        }
        $request->validate([
            'property_location_name' => 'required|unique:property_locations',
            'property_location_slug' => 'unique:property_locations',
            'property_location_photo' => 'required|image|mimes:jpeg,png,jpg,gif|max:2048',
            
            'parent_id' => 'nullable|exists:property_locations,id', // Alt kategori için parent_id kuralı eklendi
        ], [
            'property_location_name.required' => ERR_NAME_REQUIRED,
            'property_location_name.unique' => ERR_NAME_EXIST,
            'property_location_slug.unique' => ERR_SLUG_UNIQUE,
            'property_location_photo.required' => ERR_PHOTO_REQUIRED,
            'property_location_photo.image' => ERR_PHOTO_IMAGE,
            'property_location_photo.mimes' => ERR_PHOTO_JPG_PNG_GIF,
            'property_location_photo.max' => ERR_PHOTO_MAX,
            'parent_id.exists' => 'Geçerli bir üst kategori seçin', // Alt kategori için hata mesajı
        ]);
        $statement = DB::select("SHOW TABLE STATUS LIKE 'property_locations'");
        $ai_id = $statement[0]->Auto_increment;
        $ext = $request->file('property_location_photo')->extension();
        $rand_value = md5(mt_rand(11111111, 99999999));
        $final_name = $rand_value . '.' . $ext;
        $request->file('property_location_photo')->move(public_path('uploads/property_location_photos/'), $final_name);
        $property_location = new PropertyLocation();
        $data = $request->only($property_location->getFillable());
        if (empty($data['property_location_slug'])) {
            unset($data['property_location_slug']);
            $data['property_location_slug'] = Str::slug($request->property_location_name);
        }
        if (preg_match('/\s/', $data['property_location_slug'])) {
            return Redirect()->back()->with('error', ERR_SLUG_WHITESPACE);
        }
        unset($data['property_location_photo']);
        $data['property_location_photo'] = $final_name;
        $data['page_description'] = $request->input('page_description');
        $property_location->fill($data);
        // Eğer parent_id gönderildiyse ve geçerli bir üst kategori ise atanacak
        if ($request->has('parent_id')) {
            $parentCategory = PropertyLocation::findOrFail($request->parent_id);
            $property_location->parent()->associate($parentCategory);
        }
        $property_location->save();
        return redirect()->route('admin_property_location_view')->with('success', SUCCESS_ACTION);
    }
    public function edit($id)
    {
        $property_location = PropertyLocation::findOrFail($id);
        $property_locations = PropertyLocation::orderBy('id', 'asc')->get(); // Bu satırı ekledik
        return view('admin.property_location_edit', compact('property_location', 'property_locations'));
    }
        public function update(Request $request, $id)
    {
        if (env('PROJECT_MODE') == 0) {
            return redirect()->back()->with('error', env('PROJECT_NOTIFICATION'));
        }
        $property_location = PropertyLocation::findOrFail($id);
        $data = $request->only($property_location->getFillable());
        if ($request->hasFile('property_location_photo')) {
            $request->validate([
                'property_location_photo' => 'image|mimes:jpeg,png,jpg,gif|max:2048'
            ], [
                'property_location_photo.image' => ERR_PHOTO_IMAGE,
                'property_location_photo.mimes' => ERR_PHOTO_JPG_PNG_GIF,
                'property_location_photo.max' => ERR_PHOTO_MAX
            ]);
            unlink(public_path('uploads/property_location_photos/' . $property_location->property_location_photo));
            // Dosyayı yükle
            $ext = $request->file('property_location_photo')->extension();
            $rand_value = md5(mt_rand(11111111, 99999999));
            $final_name = $rand_value . '.' . $ext;
            $request->file('property_location_photo')->move(public_path('uploads/property_location_photos/'), $final_name);
            unset($data['property_location_photo']);
            $data['property_location_photo'] = $final_name;
        }
        $request->validate([
            'property_location_name'   =>  [
                'required',
                Rule::unique('property_locations')->ignore($id),
            ],
            'property_location_slug'   =>  [
                Rule::unique('property_locations')->ignore($id),
            ]
        ],[
            'property_location_name.required' => ERR_NAME_REQUIRED,
            'property_location_name.unique' => ERR_NAME_EXIST,
            'property_location_slug.unique' => ERR_SLUG_UNIQUE,
        ]);
        if (empty($data['property_location_slug'])) {
            unset($data['property_location_slug']);
            $data['property_location_slug'] = Str::slug($request->property_location_name);
        }
        if (preg_match('/\s/', $data['property_location_slug'])) {
            return Redirect()->back()->with('error', ERR_SLUG_WHITESPACE);
        }
        $data['page_description'] = $request->input('page_description');
        $property_location->fill($data);
        // Eğer parent_id gönderildiyse ve geçerli bir üst kategori ise atanacak
        if ($request->has('parent_id')) {
            $parentCategory = PropertyLocation::findOrFail($request->parent_id);
            $property_location->parent()->associate($parentCategory);
        }
        $property_location->save();
        return redirect()->route('admin_property_location_view')->with('success', SUCCESS_ACTION);
    }
    
        public function destroy($id)
        {
            if(env('PROJECT_MODE') == 0) {
                return redirect()->back()->with('error', env('PROJECT_NOTIFICATION'));
            }
            
            $tot = Property::where('property_location_id',$id)->count();
            if($tot)
            {
                return Redirect()->back()->with('error', ERR_ITEM_DELETE);   
            }
            $property_location = PropertyLocation::findOrFail($id);
            unlink(public_path('uploads/property_location_photos/'.$property_location->property_location_photo));
            $property_location->delete();
            // Success Message and redirect
            return Redirect()->back()->with('success', SUCCESS_ACTION);
        }
    }
    model
    <?php
    namespace App\Models;
    use Illuminate\Database\Eloquent\Model;
    class PropertyLocation extends Model
    {
        protected $fillable = [
            'property_location_name',
            'property_location_slug',
            'property_location_photo',
            'seo_title',
            'seo_meta_description',
            'parent_id', // data çek
            'page_description'
        ];
        // Alt kategoriyi temsil eden ilişkiyi tanımla
        public function subcategories()
        {
            return $this->hasMany(PropertyLocation::class, 'parent_id');
        }
        // Üst kategoriyi temsil eden ilişkiyi tanımla
        public function parentCategory()
        {
            return $this->belongsTo(PropertyLocation::class, 'parent_id');
        }
        public function parent()
        {
            return $this->belongsTo(PropertyLocation::class, 'parent_id');
        }
        public function children()
        {
            return $this->hasMany(PropertyLocation::class, 'parent_id');
        }
    }
    giden veri dd ile
    [LIST=1][*]_token: 
    Abt1ezpuZUSZEmUI9R3tT9AGdeXyL3FTFWsvZtqZ[*]parent_id: 
    1[*]property_location_name: 
    123213[*]property_location_slug: 
    123123[*]property_location_photo: 
    (binary)[*]page_description: [*]seo_title: 
    123213[*]
    seo_meta_description: 
    213123[/LIST]
    SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'page_description' cannot be null (SQL: insert into `property_locations` (`property_location_name`, `property_location_slug`, `page_description`, `seo_title`, `seo_meta_description`, `parent_id`, `property_location_photo`, `updated_at`, `created_at`) values (123213, 123123, ?, 123213, 213123, 1, 22d37e3758ef997daa185ed5fae133ae.png, 2023-08-16 13:07:19, 2023-08-16 13:07:19))

    işin garip tarafı 404 alıyorum arada da /admin/property-location/store createten store a atıyor bazen 404 bazende page_description null hatası
  • 16-08-2023, 16:15:20
    #2
    Tablonuzda page_description'i nullable yapın hocam. Bu arada kafasına göre hata veriyorsa veritabanı sunucusu ile ilgili bir sorun olabilir zira Laravel oldukça stabil çalışan bir framework.
  • 16-08-2023, 16:21:58
    #3
    doox adlı üyeden alıntı: mesajı görüntüle
    Tablonuzda page_description'i nullable yapın hocam. Bu arada kafasına göre hata veriyorsa veritabanı sunucusu ile ilgili bir sorun olabilir zira Laravel oldukça stabil çalışan bir framework.
  • 16-08-2023, 16:32:19
    #4
    kriz geçircem veri adı doğru modeller ekleidklerim doğru blade formdan giderken içi boş görünüyor aynı editörü diğer sayfalarda da kullanıyorum birtek bunda var bu saçmalık
  • 16-08-2023, 23:38:15
    #5
    config > database > strict'i false yapıp dener misin