Refactoring a php function at Laravel Model

I have a method at a Model like this: public function questionOwner($id) { if (auth()->user()->id == $id) { return true; }else{ return false; } } Now I wanted to refactor this function so I tried this: public function queOwner($id) { return !! auth()->user()->id == $id; } So if auth()->user()->id was not equals to $id, then… Read More Refactoring a php function at Laravel Model

Non-static method Illuminate\Http\Request::url() cannot be called statically

I’m using Laravel 9 and I want to redirect user to same page url, so I tried this: if(!$status){ alert()->error(‘Wrong code!’); return redirect(Request::url()); } And I have included as well the Request but don’t know why get this error: Non-static method Illuminate\Http\Request::url() cannot be called statically So what’s going wrong here? How can I solve… Read More Non-static method Illuminate\Http\Request::url() cannot be called statically

Laravel 9 foreignId [Foreign key constraint is incorrectly formed]

I am getting an error while using foreign keys. Products migration Schema::create(‘product’, function (Blueprint $table) { $table->id(); // Ürün adı $table->string(‘name’); //Ürün adı //$table->unsignedBigInteger(‘category_id’); $table->foreignId(‘category_id’)->constrained(‘category’); $table->timestamps(); }); Category migration Schema::create(‘category’, function (Blueprint $table) { $table->id(); $table->integer(‘main_category’)->nullable(); $table->string(‘name’); $table->integer(‘commission’); }); Error General error: 1005 Can’t create table laravel.product (errno: 150 "Foreign key constraint is incorrectly formed")… Read More Laravel 9 foreignId [Foreign key constraint is incorrectly formed]

Laravel update only refreshes a page

My update page isn’t working, when I’m submitting a form it only refreshes a page and adds some stuff to my URL, for example: http://127.0.0.1:8000/admin/employees/102/edit?_method=PUT&_token=mj3lrHqoYm1wiLwWiNQ8OX0kNRjmW4QVRuLpgZxY&image_path=&name=Libbie+Ebert&phone_number=380324244497&email=brekke.lola%40example.org&position_id=7&payment=186799&head=Asia+Frami&recruitment_date=2022-01-10. I already cleared route cache and its still not working, and also tried to use dd function but it’s not showing up. What can be wrong? My model: class Employee… Read More Laravel update only refreshes a page

Laravel can't Delete data, it can enter on destroy() function but it parameter return null

So i’m try to delete data on laravel using resource route. but the data remain and still return the function. Im also try to delete the Greens from destroy() parameter, it make $greens containing ‘id’. but still, i want to keep destroy() parameter to be (Greens $greens), not just ($greens) Controller : public function destroy(Greens… Read More Laravel can't Delete data, it can enter on destroy() function but it parameter return null

How to split words of an input by space

I have a Laravel 9 forum project and I have added this form field: <div class="create__section"> <label class="create__label BMehrBold" for="tags">Tags (separate each one by [space])</label> <input type="text" class="form-control BKoodakBold" id="tags" placeholder="Enter the keywords here"> <span id="tagshow"></span> </div> So as you can see I have said that Each tag should be separated by space. So if… Read More How to split words of an input by space

Target class [ProductController] does not exist

web.php use Illuminate\Support\Facades\Route; use App\Http\Controllers\ProductController; Route::post(‘/products/{qty}/add’, ‘ProductController@addProduct’)->name(‘addProduct’); products-list.blade.php <form action="{{ route(‘addProduct’, 1) }}" method="post" class="ui form"> <input type="text" name="qty" value="1" /> <button type="submit" class="btn btn-primary" type="button">Add</button> </form> app/Http/Controllers/ProductController.php namespace App\Http\Controllers; use Illuminate\Http\Request; class ProductController extends Controller { public function addProduct(Request $request, $qty) { dd($qty); } } But the controller class exists? >Solution : Namespacing won’t… Read More Target class [ProductController] does not exist

Laravel eloquent hasmanythrough get count

I use laravel 9.x I am trying to get the count of the Content_hashtag and combine it into the tag, I have 4 tables like the following: Chapter bp_chapter_id, bp_chapter_name, Section bp_section_id, bp_chapter_id, bp_tag_id, Content_hashtag bp_ch_id, bp_tag_id, bp_content_id Hashtag bp_tag_id, bp_hashtag_name At the model , i have using hasmanythrough like following: Chapter Model : public… Read More Laravel eloquent hasmanythrough get count