My Laravel Guide

v  Laravel Installation command
·         1st Method (Two command you have to enter)
composer global require laravel/installer
laravel new ProjectName OR laravel new ProjectName --auth (this --auth will make scaffolding )
·         2nd Method (Only one command)
            composer create-project --prefer-dist laravel/laravel newProject
v  Scafflolding command
·         composer require laravel/ui --dev
·         php artisan view --auth
v  Controller create command for creating under subfolder
·         php artisan make:controller Subfolder\ControllerName
v  Laravel URL and Route define in action/src and other…
·         <a href="{{url('logomanagement/'. $item->id .'/edit')}}"> </a>=>URL
·         <a href="{{route('admin_logomanagement_edit’, $item->id)}}"> </a>=>Route
v  Laravel Model property
·         $data = Tbl_logo::get(); // collection
·         $data = Tbl_logo::first(); // model instance
·         $data = Tbl_logo::where(‘user_id’, auth()->id)->first(); //model instance
·         $data= auth()->user()->tbl->company_avatar //model instance if u have relationship
v  Method for printing date format
·         diffForHumans()
·         <span class="date small mr-3"><i class="fa fa-calendar know-icons small" aria-hidden="true"></i> {{ \Carbon\Carbon::parse($article['created_at'])->format('j F Y ')}}  </span>
·         <td>{{ date('F d, Y',strtotime($profile->created_at)) }}<br>{{ date('g : ia',strtotime($profile->created_at)) }}</td>
v  Mail System Generating Markdown Mailable
                      php artisan make:mail userRegister --markdown=emails.orders.userregister
note: email.orders=>directory or folder name where you want to put
public function build()
{
return $this->markdown('email.orders.userregister');}
                      In Register controller add line like this
    protected function create(array $data)
    {
        $user =  User::create([
            'name' => $data['name'],
            'email' => $data['email'],
            'user_type' => 'user',
            'password' => Hash::make($data['password']),
        ]);       
        Mail::to(request('email'))->send(new userRegister($user));      
        return $user;
    }
·         Customizing the components
§  php artisan vendor:publish --tag=laravel-mail





v  Adding Recaptcha
                      Get your API key from google recaptcha.
                      Copy js script file in inside head tag.
                      Add under div tag
<div class="form-group">
                <div class="g-recaptcha{{ $errors->has('g-recaptcha-response') ? ' is-invalid' : '' }}" data-sitekey="{{env('GOOGLE_RECAPTCHA_KEY')}}">                 
                </div>
                      @if($errors->has('g-recaptcha-response'))
                          <span class="invalid-feedback" role="alert">
                              <strong>{{ $errors->first('g-recaptcha-response') }}</strong>               
                                                                                                                                </span>
                      @endif
                </div>
                      Create php artisan make:rule Captcha
<?php

namespace App\Rules;

use GuzzleHttp\Client;
use Illuminate\Contracts\Validation\Rule;

class Captcha implements Rule
{
    /**
     * Create a new rule instance.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Determine if the validation rule passes.
     *
     * @param  string  $attribute
     * @param  mixed  $value
     * @return bool
     */
    public function passes($attribute, $value)
    {
        $client = new Client();
        $response = $client->post('https://www.google.com/recaptcha/api/siteverify',
                    [
                        'form_params' => [
                            'secret' => env('GOOGLE_RECAPTCHA_SECRET', false),
                            'remoteip' => request()->getClientIp(),
                            'response' => $value
                        ]
                    ]
                );
        $body = json_decode((string)$response->getBody());
        return $body->success;
    }

    /**
     * Get the validation error message.
     *
     * @return string
     */
    public function message()
    {
        return 'Complete the reCAPTCHA to submit the form';
    }
}
                      Also add in env this
§  GOOGLE_RECAPTCHA_KEY=your_key
§  GOOGLE_RECAPTCHA_SECRET=your_secret_key
                      Add into your RegisterController validator
use App\Rules\Captcha;   
protected function validator(array $data)
    {
        return Validator::make($data, [
            'name' => 'required|string|max:255',
            'email' => 'required|string|email|max:255|unique:users',
            'password' => 'required|string|min:6|confirmed',
            // 'g-recaptcha-response' => ['required', new Captcha]//working 1st method
            'g-recaptcha-response' => new Captcha(), //second method to write
        ]);
    }

v   

Comments

Popular posts from this blog

Create Virtual Host in Localhost

User Active/Inactive using Jquery

laravel passport