dimanche 2 juin 2019

Process could not be started [The system cannot find the path specified. ] while using Mail Functionality of Laravel

While using the smtp or mailgun MAIL_DRIVER for Laravel i get the error : Process could not be started [The system cannot find the path specified. ] I am unable to figure it out the issue so far.

I tried to make sure that all the configuration etc.. are correct and tested it on a different laravel installation aswell and having same issue on that one aswell.

My .env config for smtp i tested :

MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME={removed for security}
MAIL_PASSWORD={removed for security}
MAIL_FROM_ADDRESS=from@example.com
MAIL_FROM_NAME=Example

My .env config for mailgun i tested :

MAIL_DRIVER=mailgun
MAILGUN_DOMAIN={removed for security}
MAILGUN_SECRET={removed for security}
MAILGUN_ENDPOINT={removed for security}
MAIL_FROM_ADDRESS=from@example.com
MAIL_FROM_NAME=Example

My Code which is used for sending the mail through route :

use Illuminate\Support\Facades\Mail;

Route::get('/',function(){
    $data = [
        'title' => 'Hi Example, How are You?',
        'content' => 'Testing out the mail system'
    ];

    Mail::send('emails.test',$data, function($message){
        $message->to('example@gmail.com','Example')->subject('Hello Example, Whats Up');
    });
});


My View File for the mail:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
    <h1></h1>
    <p></p>
</body>
</html>

The expected result is that it should have sent the message in case of smtp or mailgun, however it is throwing an error:

Swift_TransportException
Process could not be started [The system cannot find the path specified. ]



via Chebli Mohamed

How change updated_at from timestamp type to datetime?

Now field updated_at is as datetime(3), so it invokes an error:

errors: "Trailing data"

Because Laravel expects timestamp type instead datetime. How to say Laravel that it is datetime field?



via Chebli Mohamed

419 page expired Laravel 5.8 after login/registraion in live server

after form submit for login/registration it shows 419|page expired. I used @csrf in the form. Its working on local server. but facing the issue in live server. Any help? I have different 3 types of users and implemented multi auth for them. My code is given below:

config/auth.php

<?php

return [

    'defaults' => [
        'guard' => 'vendor',
        'passwords' => 'vendors',
    ],

    'guards' => [

        'admin' => [
            'driver' => 'session',
            'provider' => 'admins',
        ],

        'manager' => [
            'driver' => 'session',
            'provider' => 'managers',
        ],

        'vendor' => [
            'driver' => 'session',
            'provider' => 'vendors',
        ],

        'api' => [
            'driver' => 'token',
            'provider' => 'users',
            'hash' => false,
        ],
    ],

    'providers' => [

        'admins' => [
            'driver' => 'eloquent',
            'model' => App\Admin::class,
        ],

        'managers' => [
            'driver' => 'eloquent',
            'model' => App\Manager::class,
        ],


        'vendors' => [
            'driver' => 'eloquent',
            'model' => App\Vendor::class,
        ],

        // 'users' => [
        //     'driver' => 'database',
        //     'table' => 'users',
        // ],
    ],

    'passwords' => [
        'admins' => [
            'provider' => 'admins',
            'table' => 'password_resets',
            'expire' => 60,
        ],
        'managers' => [
            'provider' => 'managers',
            'table' => 'password_resets',
            'expire' => 60,
        ],
        'vendors' => [
            'provider' => 'vendors',
            'table' => 'password_resets',
            'expire' => 60,
        ],
    ],

];

RedirectedIfAuthenticated.php

public function handle($request, Closure $next, $guard = null)
    {
        switch ($guard) {
            case 'admin':
                if(Auth::guard($guard)->check()){
                    return redirect()->route('admin.dashboard');
                }
                break;
            case 'manager':
                if(Auth::guard($guard)->check()){
                    return redirect()->route('manager.dashboard');
                }
                break;
            case 'vendor':
                if(Auth::guard($guard)->check()){
                    return redirect()->route('vendor.dashboard');
                }
                break;

            default:
                if (Auth::guard($guard)->check()) {
                    return redirect('/home');
                }
                break;
        }

        return $next($request);
    }

its perfectly working locally except on live server. pls help.



via Chebli Mohamed

Laravel Some Error: htmlspecialchars() expects parameter 1 to be string, object given

After deciding several problems in project i have the last problem. At last question, I've said that i'm not PHP/Laravel developer but i need to support some project and add some fixture. And I need community help :)

app.blade.php


<!DOCTYPE html>
<html lang="ru">
<head>
    <html prefix="og: //ogp.me/ns#">
    <link as=script href="https://disney.ru/adobe/adobe_analytics_code.js" rel=preload />
    <script src="https://disney.ru/adobe/adobe_analytics_code.js"></script>
    <!-- Google Tag Manager Part 1-->
    <script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
                new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
                j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
                'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
        })(window,document,'script','dataLayer','GTM-33CDPQ');</script>
    <!-- End Google Tag Manager -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="csrf-token" content="">
    <title></title>
    <meta name="description" content="">
    <meta name="keywords" content="">
    <!-- OpenGraph -->
    <meta property="og:title" content="" />
    <meta property="og:type" content="" />
    <meta property="og:url" content="<?php echo "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]" ?>" />
    <meta property="og:description" content="" />
    <meta property="og:image" content="" />


database


mysql> SELECT og_image FROM heroes;;
+-----------------------------------------+
| og_image                                |
+-----------------------------------------+
| uploads/images/uWXGUnrZU6cHAZXyPQvT.png |
| NULL                                    |
| NULL                                    |
| NULL                                    |


How i can fixture this? And this og_image will be not only in one model Hero For example.

Thanks!



via Chebli Mohamed

How to get property from Request object Laravel?

I have POST data:

[{"id":1,"amount":0,"debit":10,"credit":0,"invoice":{"AC_code":"10","AC_name":"Qeyri-maddi aktivlər","AC_id":2}},
{"id":2,"amount":0,"debit":0,"credit":10,"invoice":{"AC_code":"18","AC_name":"Sair uzunmüddətli maliyyə aktivləri","AC_id":33}}]

I try to iterate incoming array like this:

public function update(Request $request, $id)
{
   foreach($request as $k => $value) {
     echo $value['amount']; // $value->amount
   }

}

But I get error message:

{"errors":"Cannot use object of type Symfony\\Component\\HttpFoundation\\ParameterBag as array"}



via Chebli Mohamed

laravel if use validation in controller cause white blank screen

i'm performing validation on some field in request. in my case " title " , when i use any validation in this action it give me white blank screen with no information, i tried using seprate Request validation file... if i remove validation everything will be ok! why this happening?

(php error log and laravel debugging are already on).

this is the dd() result in target controller action:

array:9 [▼
  "_method" => "POST"
  "_token" => "XW8ifwaPFlnA31mqlF3rjLz0iDyAxSpayr6G11WJ"
  "hotel_id" => "63"
  "lang" => "fa"
  "title" => null
  "meta" => null
  "keywords" => null
  "address" => null
  "cancelterms" => null
]

this is my form action:

public function addFaLang(Request $request)
{

      dd($request->all());


     $this->validate(
       $request,
         ['title' => 'required'],
         ['title.required' => 'please fill this']
     );



    $hotel_id = $request->get('hotel_id');


    $hotel_translates = HotelTranslate::where(['hotel_id' =>  $hotel_id, 'lang' => 'fa'])->count();

    if ($hotel_translates) {
        HotelTranslate::where(['hotel_id' =>  $hotel_id, 'lang' => 'fa'])->delete();
    }

    if ($request->title) {
        $hotel_tra = HotelTranslate::create($request->only( 'hotel_id', 'title', 'meta', 'keywords', 'address', 'cancel_term', 'lang'));
        $hotel_tra->save();
    }


    $result = array('result' => 1, 'idhotel' => $hotel_id, 'message' => 'success');

    return view('adminarea.hotel.create-hotel-ar-lang', $result);
}

this is my form:

form method="post" action="">
    @method('POST')
    @csrf
    <input type="hidden" name="hotel_id" value="">

    <table class="table table-bordered table-striped">
        <div class="progress">
            <div class="progress-bar progress-bar-striped" role="progressbar" aria-valuenow="40" aria-valuemin="0"
                aria-valuemax="100" style="width: 40%"></div>
        </div>
        <tr>
            <td>
                <label>زبان فارسی
                    <input type="hidden" name="lang" value="fa">

                </label>

            </td>
        </tr>
        <tr>
            <td>
                <input type="text" name="title" class="form-control " placeholder="نام هتل" style="width: 100%">
                @if ($errors->has('title'))
                <div class="invalid-feedback">
                    <strong></strong>
                </div>
                @endif
            </td>
        </tr>
        <tr>
            <td>
                <input type="text" name="meta" class="form-control" placeholder="متا" style="width: 100%">
            </td>
        </tr>
        <tr>
            <td>
                <input type="text" name="keywords" class="form-control" placeholder="کلید واژه"
                    style="width: 100%">
            </td>
        </tr>
        <tr>
            <td>
                <input type="text" name="address" class="form-control" placeholder="آدرس" style="width: 100%">
            </td>
        </tr>
        <tr>
            <td>
                <input type="text" name="cancelterms" class="form-control" placeholder="قوانین کنسلی"
                    style="width: 100%">
            </td>
        </tr>

        <tr>
            <td>
                <input type='submit' value='مرحله بعد' class='btn btn-success' style="float:left">
            </td>
        </tr>
    </table>
</form>



via Chebli Mohamed

Finding related users that matching a condition

Guys Im trying to show posts to user based on previous posts that the user liked ,seen and some followers he has. I have 3 for loops that I am checking these conditions. in the 3rd one we check if user_Id is in latest_post_seen , follower and like tables if it is we pass it to another variable and unset that BUT the problem is if I set the limit by 100 for each query , the 2nd and 3rd loop will go throw for each item in 1st loop, so 200 loops for each , would be 20,000 loops which drives me crazy!

this is the code i comeup with

$onlyDLS are the recent posts our user checked (limit 100)

$onlyLike is a query with posts he liked ( limit 100)

$followers is all the users that our user is following

 foreach($followers as $indexf=>$follower){     
        foreach( $onlyDLS as $index=>$each){
        foreach( $onlyLike as $indexl=>$eachl){
            if($follower->following_id == $index && $index == $indexl){
                $withdlsLike->push($index);//if we had follower with dls , index is user_id, and we had the user in the like
                //SINCE we are sorting the users with  posts (arsort) withdls with be in DESC order having the users with more post at top
                $flagger = true;
                    unset($onlyLike[$indexl]);
                    unset($onlyDLS[$index]);
            }
        }
        if($follower->following_id == $index){// if user_Id was not found in like then this if will be checked
                $withdlsLike->push($index);//if we had follower with dls , index is user_id

                $flagger = true;
                    unset($onlyDLS[$index]);
            }
            if($flagger == false){//if we didnt find the user_id in dls then its only a follower
                $onlyfollow->push($follower->following_id);
                unset($follower[$indexf]);
            }
        }

so each loop has 100 items at max , eachtime we found a match we unset those we have to. The first time its 20,000 , if there was not a match again 20,000.There must be a better way which I dont know.

Any suggestion is highly appreciated!



via Chebli Mohamed