json field in laravel migration

To create a JSON field, all we need to do in Laravel migration is use ->json() method:

Schema::create('products', function (Blueprint $table) {
    $table->increments('id');
    $table->string('name');
    $table->decimal('price', 15, 2);
    $table->json('properties');
    $table->timestamps();
    $table->softDeletes();
});

Next, we need to tell our model to cast that column from JSON to an array automatically:

protected $casts = [
        'properties' => 'array'
    ];

To avoid that, we need to eliminate null values from the array. I will use Eloquent mutator feature and transform the array to the one without empty values in app/Product.php model:

public function setPropertiesAttribute($value)
{
    $properties = [];

    foreach ($value as $array_item) {
        if (!is_null($array_item['key'])) {
            $properties[] = $array_item;
        }
    }

    $this->attributes['properties'] = json_encode($properties);
}

datatable default show 100

$(document).ready(function() {
$('#example').DataTable( {
"lengthMenu": [[100, "All", 50, 25], [100, "All", 50, 25]],
"pageLength": 50

} );
} );

Target class [permission] does not exist.

Add these two in app/Http/Kernel.php in protected $routeMiddleware = [] array.

'permission' => \Spatie\Permission\Middlewares\PermissionMiddleware::class,
 'role' => \Spatie\Permission\Middlewares\RoleMiddleware::class,

add deleted_at column laravel migration

  Schema::create('subject', function (Blueprint $table) {
            $table->id();          
            $table->string('subject_name',100)->nullable(); 
            $table->softDeletes();       
            $table->timestamps();
                
        });
class QuestionMaster extends Model
{
    use HasFactory;
    protected $table = 'question_master';
    protected $fillable = [
'subject',
'unit',
'topic',
'level',
'tag',
'sub_tag',
    ];
    protected $primaryKey = 'id';
    use SoftDeletes;
}

Route file example in Laravel

Route file example in Laravel 10

<?php

use App\Http\Controllers\UserController;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider and all of them will
| be assigned to the "web" middleware group. Make something great!
|
*/

Route::get('/', function () {
    return view('register');
});
Route::get('login', function () {
    return view('login');
})->name('login');

Route::post('register-user', [UserController::class, 'register']);
Route::post('login-user', [UserController::class, 'login'])->name('login-user');

Route::group(['middleware' => 'auth'], function(){
Route::get('dashboard', function () {
    return view('dashboard');
});
});   

Laravel 10 error message

Display All Error

@foreach ($errors->all() as $error)
<div class="col-12">
<div class="alert alert-warning">
{{ $error }}
</div>
</div>
@endforeach

Display Selected Error

@error('title') is-invalid @enderror

send mail in laravel

 use Mail;        

 $data = array('name'=>"Virat Gandhi");
   
      Mail::send(['text'=>'admin.mail'], $data, function($message) {
         $message->to('adityaypi@yahoo.com', 'Aditya Technology')->subject
            ('Laravel Basic Testing Mail');
         $message->from('aditya@soatechnology.net','Aditya Kumar Singh');
      });

how can i get raw data in laravel-php api from webhook and store into file

How to write code for InCall and AfterCall webhook url for Myoperator

InCall Webhook Myoperator

public function inCallWebhook(Request $request)
{
  $data = array();
  $data['data'] = json_decode(Request::createFromGlobals()->getContent());
  $input = array();
  try{
  $input['incall_id'] = $data['data']->id;
  $input['uid'] = $data['data']->uid;
  $input['reference_id'] = $data['data']->reference_id;
  $input['company_id'] = $data['data']->company_id;
  $input['clid_raw'] = $data['data']->clid_raw;
  $input['clid'] = $data['data']->clid;
  $input['rdnis'] = $data['data']->rdnis;
  $input['call_state'] = $data['data']->call_state;
  $input['event'] = $data['data']->event;
  $input['status'] = $data['data']->status;
  $input['users'] = $data['data']->users;
  $input['created'] = $data['data']->created;
  $input['call_time'] = $data['data']->call_time;
  $calIncallWebhook = new CalIncallWebhook($input);
  $calIncallWebhook->save();
  }
  catch(Exception $ex)
  {
  $fp = fopen($_SERVER['DOCUMENT_ROOT'] . "/public/incall.txt","w");
  //fwrite($fp, Request::createFromGlobals()->getContent());
  fwrite($fp, $ex->getMessage());
  fclose($fp);
  }
 
 return $this->sendResponse($data, 'Successfully');   
}

AfterCall Webhook Myoperator


public function afterCallWebhook(Request $request)
{
  $data = array();
  $data['data'] = json_decode(Request::createFromGlobals()->getContent());
  $input = array();
  try{
  $input['aftercall_id'] = $data['data']->_ai;
  $input['company_id'] = $data['data']->_ci;
  $input['caller_cr'] = $data['data']->_cr;
  $input['caller_cl'] = $data['data']->_cl;
  $input['calllocation_se'] = $data['data']->_se;
  $input['status_su'] = $data['data']->_su;
  $input['call_st'] = $data['data']->_st;
  $input['call_et'] = $data['data']->_et;
  $input['time_ss'] = $data['data']->_ss;
  $input['duration_dr'] = $data['data']->_dr;
  $input['calltype_ev'] = $data['data']->_ev;
  $input['reference_ri'] = $data['data']->_ri;
  $calAftercallWebhook = new CalAftercallWebhook($input);
  $calAftercallWebhook->save();
  }
  catch(Exception $ex)
  {
  $fp = fopen($_SERVER['DOCUMENT_ROOT'] . "/public/aftercall.txt","w");
  //fwrite($fp, Request::createFromGlobals()->getContent());
  fwrite($fp, $ex->getMessage());
  fclose($fp);
  }
  return $this->sendResponse($data, 'Successfully');     
}
public function InCallWebhookCode(Request $request)
{
  $data = array();
  $data['data'] = json_decode(Request::createFromGlobals()->getContent());
  $fp = fopen($_SERVER['DOCUMENT_ROOT'] . "/public/incall.txt","w");
  fwrite($fp, Request::createFromGlobals()->getContent());
  fclose($fp);  
  return $this->sendResponse($data, 'Successfully'); 

}
public function inCallWebhook(Request $request)
{
  $data = array();
  $aaaa['raw'] = json_decode(Request::createFromGlobals()->getContent());
  $data['data'] = json_decode($aaaa['raw']->message->data);
  $fp = fopen($_SERVER['DOCUMENT_ROOT'] . "/public/incall.txt","w");
  fwrite($fp, Request::createFromGlobals()->getContent());
OR
  fwrite($fp,  $aaaa['raw']->message->data);
  fclose($fp);
  return $this->sendResponse($data, 'Successfully');   
}

Creation of dynamic property CI_Router::$uri is deprecated Filename: core/Router.php

error in CodeIgniter website after update php 7.4 to php 8.2

how to resolve error CodeIgniter website error PHP Warning Deprecated: Creation of dynamic property is deprecated

Adding this just above the class{ will fix it:

#[\AllowDynamicProperties]

/system/core/URI.php

#[\AllowDynamicProperties]

class CI_URI {

/system/core/Router.php

#[\AllowDynamicProperties]

class CI_Router {

/system/core/Loader.php

#[\AllowDynamicProperties]

class CI_Loader {

/system/core/Controller.php

#[\AllowDynamicProperties]

class CI_Controller {   

/system/database/DB_driver.php

#[\AllowDynamicProperties]

abstract class CI_DB_driver {

Email : adityaypi@yahoo.com, Mobile : +91-9555699081