samedi 28 avril 2018

Laravel Swift_TransportException Connection could not be established with smtp.gmail.com [#0]

I've been stuck on a laravel error a while now, it states that connection could not be established [#0] instead of placing everything correctly in my env file. I'm posting my code here maybe someone can help me out with my error.

My Controller

<?php

namespace App\Http\Controllers;

use App\Order;
use Illuminate\Http\Request;
use App\Mail\OrderShipped;
use Carbon\Carbon;
use Illuminate\Support\Facades\Mail;
use App\User;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;

class OrderController extends Controller
{
    public function Orders($type='')
    {

        if($type =='pending'){
            $orders=Order::where('delivered','0')->get();
        }elseif ($type == 'delivered'){
            $orders=Order::where('delivered','1')->get();
        }else{
            $orders=Order::all();
        }
        return view('admin.orders.index',compact('orders'));
    }

    public function toggledeliver(Request $request,$orderId)
    {   
        $order=Order::find($orderId);
        if($request->has('delivered')){
            Mail::to($order->user)->send(new OrderShipped($order));
            $order->delivered=$request->delivered;            
        }else{
            $order->delivered="0";
        }
        $order->save();
        return back();
    }
}

The error occurs on Mail::to($order->user)->send(new OrderShipped($order)); line.

My OrderShipped:

<?php

namespace App\Mail;

use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;

class OrderShipped extends Mailable
{
    use Queueable, SerializesModels;

    /**
     * Create a new message instance.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Build the message.
     *
     * @return $this
     */
    public function build()
    {
        return $this->view('emails.email-shipped');
    }
}

My .env file:

APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:vmGDlc0kJ41pMM0jHoyi5PyCZ9FfQNrElxeCJKo5+PE=
APP_DEBUG=true
APP_LOG_LEVEL=debug
APP_URL=http://localhost

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=pharmacy
DB_USERNAME=root
DB_PASSWORD=

BROADCAST_DRIVER=log
CACHE_DRIVER=file
SESSION_DRIVER=file
SESSION_LIFETIME=120
QUEUE_DRIVER=sync

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=mygmail@gmail.com
MAIL_PASSWORD=XXXXXXXXXXXXXXXXXXX
MAIL_ENCRYPTION=tls

PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_APP_CLUSTER=mt1

There is only 1 line in email-shipped.blade.php

<h1> Order Shipped </h1>

Please note that i've enabled 2 step verification in my gmail account and i've been placing my application generated password in my env file with my gmail account.



via Chebli Mohamed

How to truncate variable in template Laravel 5.6?

i need your help to know how to truncate my variable in my template.

this is my code :

<p class="card-text"></p>

i would truncate this variable $new['content'] at 150 characters with '...' at end.

Can you help me please ?

I work on Laravel 5.6

Thanks all ^^



via Chebli Mohamed

how to limit registration in my laravel app?

hello i have a laravel app with registration form now anyone can register multi accounts what i want is to limit registration for 1 account per ip any one can give me an idea for that ?? here is my registration form if there is a quick solution please tell me and also i want users to use only gmail

            <h4>  </h4><span class="liner"></span>

            <div class="row">
                <div class="col-md-6 col-md-offset-2 col-sm-12">
                    <h4> Registration </h4><span class="liner"></span>
                    <div class="widget-content clearfix">
                        <form action="" method="post" class="form-horizontal" enctype="multipart/form-data">
                            {!! csrf_field() !!}
                            <div class="form-group">
                                <label for="inputEmail3" class="col-sm-3 control-label">Member Plan</label>
                                <div class="col-sm-8">
                                    <select name="price_id" id="" class="form-control" required>
                                        @foreach($price as $p)
                                            @if($p->id == $pr)
                                            <option value="" selected> -  </option>
                                            @else
                                                <option value=""> -  </option>
                                            @endif
                                        @endforeach
                                    </select>
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="inputEmail3" class="col-sm-3 control-label">Name</label>
                                <div class="col-sm-8">
                                    <input type="text" name="name" class="form-control" id="inputEmail3" placeholder="Name" required>
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="inputEmail3" class="col-sm-3 control-label">Email</label>
                                <div class="col-sm-8">
                                    <input type="email" name="email" class="form-control" id="inputEmail3" placeholder="Email" required>
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="inputEmail3" class="col-sm-3 control-label">Phone</label>
                                <div class="col-sm-8">
                                    <input type="text" name="phone" required class="form-control" id="inputEmail3" placeholder="Phone">
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="inputEmail3" class="col-sm-3 control-label">Address</label>
                                <div class="col-sm-8">
                                    <textarea name="address" id="" cols="30" rows="3"
                                              class="form-control" required></textarea>
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="inputEmail3" class="col-sm-3 control-label">Profile Picture</label>
                                <div class="col-sm-8">
                                    <input type="file" name="image" id="" required class="form-control">
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="inputPassword3" class="col-sm-3 control-label">Password</label>
                                <div class="col-sm-8">
                                    <input type="password" required name="password" class="form-control" id="inputPassword3" placeholder="Password">
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="inputPassword3" class="col-sm-3 control-label">Confirm Password</label>
                                <div class="col-sm-8">
                                    <input type="password" required name="password_confirmation" class="form-control" id="inputPassword3" placeholder="Password">
                                </div>
                            </div>
                            <div class="form-group">
                                <div class="col-sm-offset-3 col-sm-8">
                                    <button type="submit" class="btn btn-default"><i class="fa fa-send"></i> Registration</button>
                                </div>
                            </div>
                        </form>



via Chebli Mohamed

How to calcuate each colume and display then make list

I'm studying laravel Scope.

Table name is "color" here is colum info

id |  colorname 
-----------------
1      black     
2      pink
3      blue
4      pink
5      green

I would like to calculate each 'colorname' amount and display list.



via Chebli Mohamed

How to restrict users after login

How can i restrict different users after they login so they wont access directories that they are not supposed to? That means everybody should access only their directories here is my login controller

protected function sendLoginResponse(Request $request)
    {
        $request->session()->regenerate();
        $this->clearLoginAttempts($request);

        foreach ($this->guard()->user()->roles as $role) {
            if ($role->name=='Admin') {
                return redirect('issuer');
            }else if ($role->name=='Approver') {
                return redirect('approver');
            }else if ($role->name=='Issuer')
            {
                return redirect('issuer');
            }else if ($role->name=='Requester')
            {
                return redirect('requester');
            }
        }
    }
    public function logout()
    {
        Auth::logout();
        Session::flush();
        return redirect('login');
    }

here is my user Model

protected $fillable = [
        'name', 'email', 'password','active',
    ];
    protected $hidden = [
        'password', 'remember_token',
    ];
    public function roles()
    {
        return $this->belongsToMany(Role::class,'role_users');
    }

Here is my Role Model

 protected $fillable = ['name'];

    protected $primaryKey = 'id';

    public function users()
    {
        return $this->belongsToMany(User::class, 'role_users');
    }



via Chebli Mohamed

laravel 5.3 hosting issue - not loading css

I'm trying to make my laravel app live on godaddy, I moved the public folder content to the root public_html folder and the app is up and running, here is the link, css file and images are not loading. why is that?

my link to css file is gives the write path when I use inspect element on browser. but not really working.

here the code to link to css file:

<link href="" rel="stylesheet">

I also tried:

<link href="" rel="stylesheet">

and:

<link href="" rel="stylesheet">

none is working for me on hosting but working fine on localhost

my images code to link images:





via Chebli Mohamed

vendredi 27 avril 2018

Laravel 5.6 Routing - Force language in the URL

I am creating a multilingual app with Laravel 5.6.

I want to force anything the URL to specifically use the language parameter.

e.g

www.myapps.com/something/somethingelse/andmore...

would redirect to

www.myapps.com/**en**/something/somethingelse/andmore...

So far,

I have used :

  Route::prefix('{lang}')->group(function () {
    Route::get('/', 'HomeController@index')->name('welcome');
    Route::get('/XYZ', 'HomeController@XXXXFunction')->name('another');
  }); 

But how do I force a redirect to a the language?



via Chebli Mohamed