Category : laravel-8

My Laravel API is hosted on godaddy and I am call that API from localhost. Here is $.ajax({ url: ‘https://example.com/api/ali’, method: ‘POST’, data: { image: dataURL, patientname: $(‘.patientname’).attr(‘patientname’), phone: phonenum, mrid: $(‘.patientmrid’).attr(‘mrid’), }, success: function(response) { $(".btnsave").text(‘Send message’); if(response == "success"){ $(‘.alert-success’).fadeIn(300).delay(5000).fadeOut(1000); }else if(response == "notsaved"){ $(‘.alert-danger’).fadeIn(300).delay(5000).fadeOut(1000); }else if(response == "notsent"){ $(‘.alert-danger’).fadeIn(300).delay(50000).fadeOut(1000); } }, error: ..

Read more

im trying to get the latest data on database, im using this on my views : @foreach ($shows as $s) <tbody> <tr> <th scope="row">{{$loop->iteration}}</th> <td>{{$s->nama}}</td> <td>{{$s->umur}}</td> <td>{{$s->alamat}}</td> <td>{{$s->nama_ortu}}</td> <td>{{$s->posyandu}}</td> <td>{{$s->result}}</td> </tr> </tbody> @endforeach and on controller : public function showresultpasien() { $shows = DB::table(‘pasiens’)->orderBy(‘id’, ‘DESC’)->first(); return view(‘result’, compact(‘shows’)); } did i doin something wrong ? ..

Read more

I try to refactor my codes. my question is that how can I refactor a method that save data in several table in the same time? I think writing these codes is essential. In the other hand, it is too long for method in controller. can I transport some of them to Model? I have ..

Read more

Laravel (currently 8.12 | php 7.4.14) started throwing errors a few days ago when I try to execute a seeder in a subdirectory via Artisan::call. On bash this command works fine: php artisan db:seed –class=DatabaseSeedersTestingStagingTestDataSeeder But I want to execute it as: Artisan::call("db:seed –class=DatabaseSeedersTestingStagingTestDataSeeder"); The result is: Target class [DatabaseSeedersDatabaseSeedersTestingStagingTestDataSeeder] does not exist. Which is ..

Read more

While I click delete button to remove a data from laravel blade datatable it passes data with url but in controller it shows empty data. Delete button in laravel blade <button class="btn btn-outline-danger" data-toggle="modal" data-target="#destroyModal{{ $data->id }}">Delete</button> delete modal <div class="modal fade" id="destroyModal{{ $data->id }}" tabindex="-1" role="dialog" aria-labelledby="destroyModal{{ $data->id }}" aria-hidden="true"> <div class="modal-dialog modal-dialog-centered" role="document"> ..

Read more

I want to create a model in Laravel named ‘Match’. When I try to do this, I get an error: syntax error, unexpected token "match", expecting identifier. When I add a character (for example: ‘Matcha’), the error goes away. I am using this code in composer.json: "require": { "php": "^7.3|^8.0", "beyondcode/laravel-websockets": "^1.12", "fruitcake/laravel-cors": "^2.0", "guzzlehttp/guzzle": ..

Read more

I want to force https SSL on my Laravel 8 production project. Adding this to htaccess does the job for me. #Force SSL RewriteCond %{HTTPS} !on RewriteRule ^.*$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] I also added this to the boot method of the AppServiceProvider if($this->app->environment(‘production’)) { URL::forceScheme(‘https’); $this->app[‘request’]->server->set(‘HTTPS’, true); } Now, Laravel 8 creates a default htaccess file ..

Read more

I am trying to implement Logout functionality on my Laravel app with TALL stack, I am firing logout event from my blade via Livewire wire:click but it doesn’t seem to fire any method from its own component. Loading my component in app.blade.php layout: <li class="flex"> @livewire(‘logout’) </li> logout.blade.php <a wire:click="logout" class="some-classes" > <svg class="w-4 h-4 ..

Read more

@throws IlluminateContractsContainerBindingResolutionException @throws IlluminateContractsContainerCircularDependencyException */ public function build($concrete) { // If the concrete type is actually a Closure, we will just execute it and // hand back the results of the functions, which allows functions to be // used as resolvers for more fine-tuned resolution of these objects. if ($concrete instanceof Closure) { return $concrete($this, ..

Read more

I’m working with Laravel 8 to develop my project and I have made this Migration: public function up() { Schema::create(‘activation_codes’, function (Blueprint $table) { $table->id(); $table->unsignedBigInteger(‘user_id’); $table->foreign(‘user_id’)->references(‘id’)->on(‘users’)->onDelete(‘cascade’); $table->string(‘code’); $table->boolean(‘used’)->default(false); $table->dateTime(‘expire’); $table->timestamps(); }); } And at the Model I added this: protected $fillable = [‘user_id’,’code’,’used’,’expire’]; public function scopeCreateCode($query, $user) { $code = $this->code(); return $query->create([ ‘user_id’ ..

Read more

I have two tables with one-to-many relationships. I followed the documentation and specified everything needed for the tables–the table’s name and primary key’s name; foreign key and local key in belongsTo() and hasMany(). But it still doesn’t work, why? Pengguna.php <?php namespace AppModels; use IlluminateDatabaseEloquentFactoriesHasFactory; use IlluminateDatabaseEloquentModel; class Pengguna extends Model { use HasFactory; protected ..

Read more

I have a user model with hasMany relationship. User has many unreviewed files and im trying to get the total number of unreviewed files. this is how i did it. i just wonder if there is a better way. $users = User::families()->whereHas(‘unreviewedcovidfiles’)->withCount(‘unreviewedcovidfiles’)->get(); $totalfiles = 0; foreach($users as $user){ $totalfiles += $user->unreviewedcovidfiles_count; } return $totalfiles; Source: ..

Read more

this works perfectly fine return Webinar::query() ->withCount(‘users’)->orderByDesc(‘users_count’) ->get(); but I need to use a condition for sorting, but this doesnt work return Webinar::query() ->where(function($query) use ($sort_by) { if($sort_by == 0) { return $query->withCount(‘users’)->orderByDesc(‘users_count’); } else { return $query->withCount(‘review’)->orderByDesc(‘review_count’); } }) ->get(); I also tried a condition inside like this to check my if else function ..

Read more

I started a new laravel 8 project and installed the laravel breeze auth starter kit. After that i made an api endpoint and i want to validate the post request going to that endpoint so i wrote some code: $validation = Validator::make($request->all(), [ ‘project_name’ => ‘required’, ‘project_location’ => ‘required’, ‘project_tasks’ => ‘required’, ]); if ($validation->fails()) ..

Read more

I have a domain: www.example.com My Laravel 8 Production Project is setup to "force" SSL on the URL. I have set this up as follows: public/.htaccess #SSL force RewriteEngine On RewriteCond %{HTTPS} !on RewriteRule ^.*$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] and app/Providers/AppServiceProvider public function boot() { if($this->app->environment(‘production’)) { URL::forceScheme(‘https’); } } my .env file APP_NAME=NameOfApp APP_ENV=production APP_KEY=*hidden* APP_DEBUG=false ..

Read more

So I have a query: $order = Orders::with(‘comments’) ->where(function ($query) { $query->where(‘data_checked’,0); })->where(function ($query) { $query->where(‘status’, ‘new’) ->orWhere(‘status’, ‘confirmed’) ->orWhere(‘status’, ‘dispatch’); }) ->first(); each comment has created_at and I am trying to order comments by created_at. How can I achieve something like that? Sourc..

Read more

I am working on an API authentication application with Laravel 8.79.0 and Sanctum. As far as I have seen, Sanctum is included in this version of Laravel, so I have not installed it myself but only uncommented this line from appHttpKernel.php: // LaravelSanctumHttpMiddlewareEnsureFrontendRequestsAreStateful::class, In routesapi.php, I have: Route::post(‘/register’, [AuthController::class, ‘register’]); Route::post(‘/login’, [AuthController::class, ‘login’]); Route::middleware(‘auth:api’)->get(‘/user’, function ..

Read more