Category : laravel-8

I want to pass an additional parameter from controller to collection resource, Please have a look at the following code, I don’t know why It’s not working. I might be doing something wron here, please help Controller $batchStudents = $batch->students->except($batch->host->id); $batchStudents->test = ‘This is testing’; $students = UserCollection::collection($batchStudents); Collection: class UserCollection extends JsonResource { return ..

Read more

I am learning laravel 8, I keep getting this error BadMethodCallException Call to undefined method AppModelsQuestion::factory() at C:UsersUSERDesktoplaravelsqnavendorlaravelframeworksrcIlluminateSupportTraitsForwardsCalls.php:50 46▕ * @throws BadMethodCallException 47▕ */ 48▕ protected static function throwBadMethodCallException($method) 49▕ { ➜ 50▕ throw new BadMethodCallException(sprintf( 51▕ ‘Call to undefined method %s::%s()’, static::class, $method 52▕ )); 53▕ } 54▕ } • Bad Method Call: Did ..

Read more

I’m trying to create a simple search for hotels with live-wire, website is multi language English and Arabic. Search works properly in English only, when I switch into Arabic, The query run properly but the returned value from database is in English. protected function current_locale() { return LaravelLocalization::getCurrentLocale() == ‘ar’ ? ‘_ar’ : ”; } ..

Read more

In laravel 8 I am trying to install laravel clockwork where i have php version 8.0.3 When I run composer require itsgoingd/clockwork command i got this error Installing itsgoingd/clockwork (v5.0.8): Extracting archive Install of itsgoingd/clockwork failed Installation failed, reverting ./composer.json and ./composer.lock to their original content. [UnexpectedValueException] ‘C:xampphtdocstest/vendor/composer/tmp-454cb94cbea8cdcf70c06a4e0164fbba’ is not a zip archive. require [–dev] ..

Read more

I’m working on a questionnaire project and I ran into an error saying: Undefined index: exams This happened when I was trying to store responses to my database. Here is my controller code: public function store(Math $math) { $data = request()->validate([ ‘responses.*.answer_id’ => ‘required’, ‘responses.*.question_id’ => ‘required’ ]); $exam = $math->exams()->create($data[‘exams’]); $exam->examanswers()->createMany($data[‘examanswers’]); return ‘Thank You’; ..

Read more

I have a bunch of columns in a table what I need is to filter the table using few parameters using laravel Eloquent ORM. For example companyName, StartDate. what I have tried is below $objFetch = OpenOrder::where(‘companyName’, $request->majorCompanies) ->orwhereBetween( ‘StartDate’, array($request->startDate_start, $request->startDate_end) ) ->orderby(‘id’, ‘desc’)->get(); return response()->json([ ‘success’ => true, ‘objects’ => $objFetch ]); "objects": ..

Read more

I have the following code to create, load and update some data from specific folder into my DB: static function create_load($file_info,$prefix){ $table_name=$prefix.’_’.Carbon::now()->format("Y_m_d_his"); DB::statement("CREATE TABLE IF NOT EXISTS gathering_db.".$table_name." ( `id` bigint unsigned NOT NULL AUTO_INCREMENT, `m_id` int unsigned DEFAULT NULL, `source` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL, `destination` varchar(30) CHARACTER SET utf8mb4 COLLATE ..

Read more

So I want to set the default value of the column order equal to the id. This is pretty much for sorting purposes. Is there anyway to do it? Or would there be a better way to achieve the same purpose? Schema::create(‘posts’, function (Blueprint $table) { $table->id(); $table->string(‘title’); $table->bigInteger(‘order’); $table->string(‘path’); $table->text(‘description’)->default(”); $table->timestamps(); }); Sourc..

Read more

laravel belongstomany same table error: Not unique table/alias. Help me please. class Categories extends Model { use HasFactory; protected $fillable = [ ‘name’, ‘parent_id’, ‘slug’, ‘title’, ‘description’ ]; public function categories(){ return $this->belongsToMany(Categories::class, ‘categories’, ‘id’, ‘parent_id’ ); } } Sourc..

Read more

Schema::create(‘course’, function (Blueprint $table) { $table->integer(‘courseId’)->autoIncrement(); $table->string(‘courseDisplayName’); $table->string(‘courseUniqueName’)->unique(); $table->string(‘courseAddedBy’); $table->dateTime(‘createdOn’); $table->dateTime(‘lastUpdated’); $table->softDeletes(); }); Above given is my course table. To rename the courseId column in it to id, i used the below code. Schema::table(‘course’, function (Blueprint $table) { $table->renameColumn(‘courseId’, ‘id’); }); it shows the migration error – IlluminateDatabaseQueryException SQLSTATE[42703]: Undefined column: 7 ERROR: column "courseid" ..

Read more

$users = DB::table(‘users’) ->join(‘course’, ‘users.id’, ‘=’, ‘course.courseId’) ->join(‘skills’, ‘users.id’, ‘=’, ‘skills.id’) ->join(‘subjects’, ‘users.id’, ‘=’, ‘subjects.id’) ->get(); dd($users); This gives me an empty result like this- items: []. I would like to join the 4 tables – users, course, skills & subjects and fetch all the datas in all the 4 tables. users table has the ..

Read more

I have created a Laravel application. After successful login to an account, Laravel makes two cookies which are Laravel_session and XSRF-TOKEN. When I just simply copy the Laravel_session and paste it into another browser or another computer’s browser then it opens the same account. "laravel_session" = "eyJpdiI6IjRwK0VjSDR1c0JGQU9lNDF…" Please, tell me how can I prevent it. ..

Read more

I have created a Laravel application. After successful login to an account, Laravel makes two cookies which are Laravel_session and XSRF-TOKEN. When I just simply copy the Laravel_session and paste it into another browser or another computer’s browser then it opens the same account. "laravel_session" = "eyJpdiI6IjRwK0VjSDR1c0JGQU9lNDF…" Please, tell me how can I prevent it. ..

Read more

I can not speak English well. Iam Sorry. i want to do, get all categories to which the category with id 5 is attached where is error editing ? Database: Categories.php class Categories extends Model { use HasFactory; protected $fillable = [ ‘name’, ‘parent_id’, ‘slug’, ‘title’, ‘description’ ]; public function parentCategories(){ return $this->belongsToMany(Categories::class); } } ..

Read more

I am trying to consume one POST api using guzzlehttp In my laravel project. But i am getting one error on my dev server. This working perfectly on my local system. $postArray is manipulating correctly both side. This is my composer version. "guzzlehttp/guzzle": "^7.3", If any one know about this please help me out. $response ..

Read more