Skip to content

Instantly share code, notes, and snippets.

View moradi-morteza's full-sized avatar
💭
I may be slow to respond.

Developer moradi-morteza

💭
I may be slow to respond.
  • Tehran,Qom
View GitHub Profile
@moradi-morteza
moradi-morteza / relation.php
Last active December 30, 2019 07:42
[relation] #LaravelT
// belongs to - one to one - one to many - many to mayn
class PostModel extends Model
{
protected $fillable =['title','des','user_id'];
public function user(){
return $this->belongsTo(User::class);
// return User::findOrFail($this->user_id);
}
}
@moradi-morteza
moradi-morteza / laravel 6.php
Last active December 14, 2020 15:46
[Laravel Start]
new laravel --auth
//add custom lib ----------------------------------------------------
npm install @fortawesome/fontawesome-free --save // icon library V:5.13
// in resource css app.scss add
@import '~@fortawesome/fontawesome-free/scss/fontawesome';
@import '~@fortawesome/fontawesome-free/scss/regular';
@import '~@fortawesome/fontawesome-free/scss/solid';
@import '~@fortawesome/fontawesome-free/scss/brands';
----------------------------------------------------------------
@moradi-morteza
moradi-morteza / email.php
Last active December 26, 2020 07:45
[email] #LaravelT
// important in localhost :
MAIL_USERNAME=bambboapp@gmail.com
MAIL_PASSWORD=112859112859
MAIL_ENCRYPTION=tls
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_FROM_ADDRESS=bambboapp@gmail.com
MAIL_FROM_NAME=bambboapp
@moradi-morteza
moradi-morteza / event.php
Last active December 22, 2019 17:53
[Event] #LaravelT
php artisan make:event RegisterUser // this event actioned
// in class EventServiceProvider
protected $listen =[
Registered::class=>[
SendEmailVerificationNotification::class,
],
RegisterUser::class=>[
@moradi-morteza
moradi-morteza / gete_policy.php
Last active December 22, 2019 17:53
[Gate and Policy] #LaravelT
$user=auth()->user();
$post=Post::where('user_id',1)->first();
$allow=\Gate::allows('update-post',$post); // not need to send user it use current logined user
// if user not logined allow is false
// if you want to user another user for check a gate
$allow=\Gate::forUser(User::find(2))->allows('update-post',$post);
if($allow){
@moradi-morteza
moradi-morteza / job.php
Last active April 11, 2020 06:55
[job] #LaravelT
<?php
---in file config queue you should change QUEUE_CONNECTION------> in env QUEUE_CONNECTION=database -------> reset config env in command
php artisan queue:table // create a migration for jobs
php artisan make:job SendVerificationEmailJob
// where you want to do :
SendVerificationEmailJob.dispatch($user);
@moradi-morteza
moradi-morteza / api.php
Last active July 6, 2020 07:09
[api Exception Handler]
// very important
1- use
Content-Type: application/json
Accept: application/json
** you should for every request set customRequest
in all of your api client request.
2- to avoid show server error in client
@moradi-morteza
moradi-morteza / api.auth.php
Last active July 6, 2020 07:23
[api/auth]
// this file contain 3 part
//1-simple auth system rest api with mobile
//3-simple auth system rest api with email
//3- passport api auth system - we do not use default auth laravel beacuse it is session base
// add $table->string('api_token')->nullable(); to user migration
// 1 - With Mobile
@moradi-morteza
moradi-morteza / passport.php
Last active January 7, 2020 07:54
[passport]
composer require laravel/passport
php artisan migrate
php artisan passport:install
//2- in Class AuthServiceProvider:
public function boot()
{
$this->registerPolicies();
Passport::routes(); // if you donot want to user route comment this line
@moradi-morteza
moradi-morteza / website-scraper.php
Created January 12, 2020 13:11
[Website Scraper]
https://ourcodeworld.com/articles/read/374/how-to-download-the-source-code-js-css-and-images-of-a-website-through-its-url-web-scraping-with-node-js
npm install website-scraper
// create a file index.js
const scrape = require('website-scraper');
let options = {