1589785384
☑ Event Listeners ($dispatchesEvents property)
☑ Model’s boot method
☑ Observers
☑ Example of Observers
https://www.youtube.com/watch?v=7GUaH6BI_V0
#laravel #php
1595201363
First thing, we will need a table and i am creating products table for this example. So run the following query to create table.
CREATE TABLE `products` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
`description` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` datetime DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
Next, we will need to insert some dummy records in this table that will be deleted.
INSERT INTO `products` (`name`, `description`) VALUES
('Test product 1', 'Product description example1'),
('Test product 2', 'Product description example2'),
('Test product 3', 'Product description example3'),
('Test product 4', 'Product description example4'),
('Test product 5', 'Product description example5');
Now we are redy to create a model corresponding to this products table. Here we will create Product model. So let’s create a model file Product.php file under app directory and put the code below.
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Product extends Model
{
protected $fillable = [
'name','description'
];
}
Now, in this second step we will create some routes to handle the request for this example. So opeen routes/web.php file and copy the routes as given below.
routes/web.php
Route::get('product', 'ProductController@index');
Route::delete('product/{id}', ['as'=>'product.destroy','uses'=>'ProductController@destroy']);
Route::delete('delete-multiple-product', ['as'=>'product.multiple-delete','uses'=>'ProductController@deleteMultiple']);
#laravel #delete multiple rows in laravel using ajax #laravel ajax delete #laravel ajax multiple checkbox delete #laravel delete multiple rows #laravel delete records using ajax #laravel multiple checkbox delete rows #laravel multiple delete
1595223780
In the today’s technogy age real time data has become an essential thing. So here, in this article i will share laravel real time event broadcasting with socket.io. Here in this example we will see how can we broadcast real times events.
Basically, to acheive this thing in our laravel application, we will use predis which is a laravel package, queue, socket.io, laravel-echo-server and event broadcasting.
So, we will need to install the above things which are not provided in the laravel appication by default. I will provide all the step to implement real time broadcasting event in the various steps from a fresh installation of laravel application. If you have already installed laravel application then you can directly jump on the next step. So without wasting our time let’s start the implementation process and follow all the steps as given below.
For installing fresh laravel application, you will just needto run the following command in your terminal or command prompt.
composer create-project --prefer-dist laravel/laravel realtimeapp
I have given a name realtimeapp to this application, you are frre to give the name of your choice.
Now, run the following command to give permission to the storage and cache directories.
sudo chmod -R 777 /var/www/html/realtimeapp/storage
sudo chmod -R 777 /var/www/html/realtimeapp/bootstrap/cache<br><br>
In this second step, we will need to install predis. So open your terminal and run the following command.
composer require predis/predis
composer require predis/predis
Now we will need to create an event for broadcasting and in the event file we will set channal and write message. So run the following command to create event.
php artisan make:event SendMessage
Above command will create an event file SendMessage.php file under app/Events directory. So open this file and update it like below.
app/Events/SendMessage.php
<?php
namespace App\Events;
use Illuminate\Broadcasting\Channel;
use Illuminate\Queue\SerializesModels;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;
class SendMessage implements ShouldBroadcastNow
{
use InteractsWithSockets, SerializesModels;
public $data = ['asas'];
/**
* Create a new event instance.
*
* @return void
*/
public function __construct()
{
}
/**
* Get the channels the event should broadcast on.
*
* @return \Illuminate\Broadcasting\Channel|array
*/
public function broadcastOn()
{
return new Channel('user-channel');
}
/**
* The event's broadcast name.
*
* @return string
*/
public function broadcastAs()
{
return 'UserEvent';
}
/**
* The event's broadcast name.
*
* @return string
*/
public function broadcastWith()
{
return ['title'=>'Notification message will go here'];
}
}
#laravel #how to broadcast events in laravel #laraevl socket.io #laravel broadcasting event #laravel event broadcasting #laravel realtime event broadcasting with socket.io
1597487833
Here, i will show you how to create dynamic depedent country state city dropdown list using ajax in laravel.
Follow Below given steps to create dynamic dependent country state city dropdown list with jQuery ajax in laravel:
https://www.tutsmake.com/ajax-country-state-city-dropdown-in-laravel/
#how to create dynamic dropdown list using laravel dynamic select box in laravel #laravel-country state city package #laravel country state city drop down #dynamic dropdown country city state list in laravel using ajax #country state city dropdown list using ajax in php laravel #country state city dropdown list using ajax in laravel demo
1625034420
Today I will show you How to Send E-mail Using Queue in Laravel 7/8, many time we can see some process take more time to load like payment gateway, email send, etc. Whenever you are sending email for verification then it load time to send mail because it is services. If you don’t want to wait to user for send email or other process on loading server side process then you can use queue.
#how to send e-mail using queue in laravel 7/8 #email #laravel #send mail using queue in laravel 7 #laravel 7/8 send mail using queue #laravel 7/8 mail queue example
1595205933
Hello guys, sometimes while working on the large application, we need to create some very small modules like simple CRUD. So here in this article i will let you know laravel create model migration and controller in a single command.
We will run a single artisan command to create model. migration and controller. We can also create resource controller by giving parameter.
We can these model, migration and controller from three command but for time saving laravel provides feature to create thses three thing by one single command.
So for desired result open your terminal and run the following command.
php artisan make:model --migration --controller Product --resource
Here, we have create product model, migration and product controller with all the resources methods.
We can also write this command in the short form like below.
php artisan make:model -mc Product --resource
You can also write this command in a more short way like below.
php artisan make:model Product -mcr
**Note: **Here, m represents migration, c represents controller and r represents as resource.
After running the above command you will get the output like
Model created successfully
Created migration (migration file name with current date and migration name )
Controller created successfully.
You can also read the article to create to add a column in the existing table through migration by clicking on the link below.
#laravel #create controller resource and model in a command #laravel artisan command #laravel create model #laravel single command for model and migration #migration and controller