Posts

Showing posts with the label Laravel

HTTPS Setup With Certbot in Digital Ocean Droplets

For Installation sudo apt install python3-certbot-apache For Activation sudo certbot --apache --expand -d domainname.com

Plain php text showing issue solve

Solution: 1 sudo systemctl status php8.1-fpm sudo apt-get install php8.1-fpm sudo apt install apache2 libapache2-mod-fcgid sudo apt install libapache2-mod-fcgid sudo a2enmod actions fcgid alias proxy_fcgi Solution: 2 sudo a2dismod mpm_event sudo systemctl restart apache2 sudo a2enmod mpm_prefork sudo systemctl restart apache2 sudo a2enmod php7.0 sudo systemctl restart apache2

Server setup basic guide

 BASIC GUIDE ssh root@192.168.0.1 -p 22 adduser hasib ssh -l hasib 192.168.0.1 Update OS Install Apache Install MySQL Install PHP Install Composer (Composer install and globalization) sudo php /tmp/composer-setup.php --install-dir=/usr/local/bin –filename=composer Install Git Set DNS Server Name to Domain Name Provider Panel

SQL query with multiple database and different tables in Laravel

DB::select("SELECT db1.employees.name AS employee_name, db2.companies.name as company_name FROM db1.employees employees JOIN db2.companies companies ON companies.code = employees.company_code WHERE companies.country = 'Bangladesh' "); Note: Both database users and passwords have to be the same.

Laravel Event Listener for keeping history

App\Providers\EventServiceProvider.php protected $listen = [     'App\Events\ResolveHistoryEvent'=>[         'App\Listeners\ResolveHistoryEventListener'     ] ]; php artisan event:generate App\Modules\Tickets\Controllers\TicketsController.php public function reopenTicket($ticketId){     $ticket = Tickets::find($ticketId);     $ticket->resolve_status = 2;     $ticket->reopen_time = Carbon::now();     $ticket->save();     event(new ResolveHistoryEvent($ticket));     return redirect('tickets/active-list')->with('flash_success','Ticket reopen successfully!'); } App\Events\ResolveHistoryEvent.php public $resolveHistory; public function __construct($ticket) {     $this->resolveHistory = $ticket; } App\Listeners\ResolveHistoryEventListener.php public function recordTicketResolveHistory($ticket){     $resolveHi...

Shortcut way to get fillable fields from a large table for Laravel Model

SELECT CONCAT('"',COLUMN_NAME,'",') as fillable FROM information_schema.columns WHERE table_name = 'my_table';

Problem : Max can not return max value from varchar type field.

Problem : Max can not return max value from varchar type field. ELOQUENT Query : $maxLicence = Agency::where('is_approved',1)->max('license_no'); RAW SQL Query : select max(test_value) from area_info; Solution :  $maxLicence = DB::select("select max(cast(agencys.license_no as int)) as license from agencys");

DB::raw() Query in Eloquent ->get();

ParkInfo::leftJoin('park_block_setup as block','block.park_id','=','park_info.id')     ->where('park_info.is_archive', 0)     ->groupBy('park_info.id')     ->orderBy('park_info.park_name', 'asc')     ->get([         'park_info.*',         DB::raw('ifnull(sum(block.has_land),0) has_land'),         DB::raw('ifnull(sum(block.has_space),0) has_space')     ]);

Laravel Eloquent Joining Query (Multiple clauses of purpose in joining)

return TableA::leftJoin('table_b as b',function($join){                 $join->on('b.foreign_id','=','table_a.id');                 $join->where('b.status','=',1);             })             ->where('table_a.group_name','emmet')             ->groupBy('b.color')             ->get([                 'table_a.*'                 DB::raw('SUM(b.price) as total_price')             ]);

Google Login Adding In Laravel

.env file: GOOGLE_LOGIN_CLIENT_ID= 4682799 66203- 3c47dfkknjj28irumub6c7vtp3dph2 oq.apps.googleusercontent.com GOOGLE_LOGIN_SECRET_KEY= vfXcMYMWPHkR3wjKhVikaCDY composer.json file :  "laravel/socialite": "^2.0" composer update config/app.php file: Provider: //  Laravel Auth Login service provider         Laravel\Socialite\ SocialiteServiceProvider:: class, Alias: // Socialite         'Socialite' => Laravel\Socialite\Facades\ Socialite::class, config/services.php file: 'google' => [         'client_id' => env('GOOGLE_LOGIN_CLIENT_ID'),         'client_secret' => env('GOOGLE_LOGIN_SECRET_KEY') ,         'redirect' => ' http://localhost:8000/auth/ google/callback ',     ],

Object to array conversion

$examTypes = ExamType::lsits('exam_name','id'); $questionTypes = json_decode(json_encode($examTypes), True );

List Query for select box in Laravel

ExamType::lists('exam_name','id');

Run project in custom host and custom port

Running Laravel Project php artisan serve --host=192.168.200.100 --port=8000 Normally php -S localhost:8080 -t public

LARAVEL CUSTOM VALIDATION

NID Validation :) 1> app/Providers/AppServiceProvider.php public function boot(){    $this->app['validator']->extend('nid',function($attribute,$value,$parameters){    $length = strlen($value);    if(in_array($length,[10,13,17])){        return true;    }else{        return false;    } }); } 2> resources/lang/en/validation.php return [    'nid' => 'The :attribute valid NID must be 10 | 13 | 17', ];

LARAVEL STYLE and SCRIPT LINKING

CSS LINKING : {!!Html::style('assets/css/bootstrap.css')!!} JAVASCRIPT LINKING : {!!Html::script('assets/js/bootstrap.min.js')!!}

LARAVEL FORM AND INPUT BOX WITH VALIDATION FORMAT

{{ Form::open(array('url'=>'action_route','method'=>'post')) }}   <div class="form-group {{$errors->has('first_name')?'has-error':''}}">     {!!Form::label('first_name','First Name : ')!!}    {!!Form::text('first_name',$info->first_name,array('class'=>'form-control'))!!}    {!!$errors->first('first_name','<span class="help-block">:message</span>')!!}   </div> {{ Form::close() }}

ul->li active class in laravel

{!! Request::segment(1)== 'contact' ? ' class="active" ' : '' !!}

DIFFERENT BETWEEN {{ }} and {!! !!} in LARAVEL

{{ }} $first = "<b>Hasib Kamal</b>" ; {{ $first }} Output : <b>Hasib Kamal </b> {!! !!} $first = "<b>Hasib Kamal</b>" ; {!! $first !!} Output : Hasib Kamal

LARAVEL(SAVE,VIEW,DELETE)

VIEW :     public function index(){         $info_list = infoModel::all();         return view('list',compact('info_list'));     } SAVE :     public function storeInfo(Request $request){         $first_name = $request->get('first_name');         $last_name = $request->get('last_name');         $email_address = $request->get('email_address');         $phone_number = $request->get('phone_number');         $info = new infoModel();         $info->first_name = $first_name;         $info->last_name = $last_name;         $info->email_address = $email_address;         $info->phone_num...

LARAVEL DOWNLOAD BY COMPOSER

DOWNLOAD THE CURRENT PROJECT -> composer create-project laravel/laravel project-name DOWNLOAD THE PROJECT VERSION WISE -> composer create-project --prefer-dist laravel/laravel project-name 5.1