mercredi 29 août 2018

Can a view check if the page is 404?

My 404.blade.php view is using my default layout, but if the page is 404 i want to hide some views I include in the default layout. Is this possible?

Something like

@if ($page->notFound)

Or do I really have to create a custom layout to use in the 404 view.



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2LDkLxh
via IFTTT

PayU POST confirmation validation

I have an API service that should be requested only by Payu. I need ideas about how to validate this.

For example: Edit allowedOrigins

I don't know if there is a Payu service that confirm that the request has been made from their servers.



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2MzVFVk
via IFTTT

how to extend a view having dynamic data in laravel

From a controller method i send $notifications to the home view and display notifications on header of my website.

The Profile views extends the home view, and i also wanted to display the notifications on profile view.

But it generates an error that undefined variable $notifications when i request for profile view.

I think one solution is that to send $notifications when returning profile view from controller method, but in website there are many views on which i wanted to show notification tab so it's the right way that i am thinking.

here is the code in the home view in the header section

<ul class="dropdown-menu" id="notificationlist">
            @foreach($notifications as $notification)
        <li><a href="" class="dropdown-item">
                <img src="http://localhost/webproject/public/user_images/" class="img-thumbnil" width="20px" height="20px"> <strong></strong>
                <span style="white-space: initial;">sent you a friend request.</span>
                </a></li>
                @endforeach
                </ul>



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2ojJSMh
via IFTTT

How to 'use' packages in my own Laravel middleware?

I wrote a localization middleware in Laravel using the LaravelGettext package which looks like this:

<?php

namespace App\Http\Middleware;

use Closure;

class Locale {

    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next) {
        if ($request->method() === 'GET') {
            $segment = $request->segment(1);

            if (!in_array($segment, config('laravel-gettext.supported-locales'))) {
                $segments = $request->segments();
                $fallback = session('locale') ?: config('laravel-gettext.fallback-locale');
                $segments = array_prepend($segments, $fallback);

                return redirect()->to(implode('/', $segments));
            }

            session(['locale' => $segment]);
            LaravelGettext::setLocale($segment);
        }
        return $next($request);
    }

}

I am routing into the middleware via:

Route::prefix('{lang?}')->middleware('locale')->group(function () {
    ...
}

Running through the middleware gives me this error though:

"Class 'App\Http\Middleware\LaravelGettext' not found"

So I figured I might have to import the LaravelGettext package manually by adding:

use Xinax\LaravelGettext\LaravelGettext;

Which now gives me this Exception:

"Non-static method Xinax\LaravelGettext\LaravelGettext::setLocale() should not be called statically"

Which makes me wonder: Is there even a valid option to access the package inside a middleware? Or did I drive into a design flaw here?



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2wqLura
via IFTTT

How can I include js files correspondes to render files in laravel blade template?

In my laravel app I have app.blade.php with following code

<html>
    <body>
        <div>
            @yield('content')
        </div>
        <script src="" ></script>
        <script src="" ></script>
    </body>
</html>

I have several pages such as page1, page2 etc and each page is rendering as page1.blade.php etc and these pages has separate javascript files like page1.js, page2.js.

page1.js should be included with page1.blade.php only and same for page2.js also. How can I include js files for the corresponding blade files?

My page1.blade.php is

@extends('layouts.app')

@section('content')
<section class="content-header">
  <h1>
    Page 1
  </h1>

</section>
@endsection



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2MTt2C7
via IFTTT

Does Laravel cache polymorphic calls?

Got a polymorphic relationship like this: User -> polymorph -> subscription from various platforms. Toy but working example:

class Polymorph
{
    ...
    public function user()
    {
        return $this->belongsTo(User::class);
    }

    public function subscription()
    {
        return $this->morphTo();
    }

    public function isExpired()
    {
        return $this->subscription->isExpired(); // Checks an attribute
    }

    public function isActive()
    {
        return $this->subscription->isActive(); // Checks an attribute
    }
    ...
}

class User{
    ...
    public function poly()
    {
        return $this->hasOne(Polymorph::class);
    }
    ...
}

And I'm doing:

$poly = $user->poly
$poly->isExpired(); // One DB call
$poly->isActive(); // No DB call
// etc..

It seems like Laravel caches the $this->subscription call. I'm looking at a query log as I'm calling these methods, and there is only one SELECT for the appropriate subscription object.

I looked through the docs, but don't think I found anything about it. Is it being cached? If so, what is it called or is there documentation describing it?



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2POZHHu
via IFTTT

SSH connection via PHP - Laravel

Hello everyone

I'm going to try to explain my problem as clear as possible, feel free to ask me more precision if you didn't understand what I meant and forgive my English this is not my mother tongue.


My goal

What I want to do looks simple. Let's say I have 2 servers: S1 and S2.
S1 is the server on which one I have my Laravel 5.5 installed and running.
S2 is a server where I have multiples PHP scripts.
I want to run a PHP script (which is on S2) from a simple click on a button in my Laravel App.
The command I want to run is php theNameOfMyFiles


The things you have to know

  1. In command line, I can connect in SSH to S2 via S1: ssh -tt -p 2222 myRemoteUser@myRemoteIp. This is working properly.
  2. Most of my test will show some tries of folder creation because it is easier to see if a folder has been created instead of checking if a script is running.

My different tries

To reach that goal, I tried a bunch of things. First of all, I am using Laravelcollective SSH 5.2 to be able to use SSH from my Laravel app.
My configuration file config/remote.php, this is where I specify my remote server connections :

return [
    default' => 'S1',
   'connections' => [
    'S1' => [
        'host'      => '127.0.0.1',
        'username'  => 'myUsername',
        'password'  => 'myPassword',
        'key'       => '',
        'keytext'   => '',
        'keyphrase' => '',
        'agent'     => '',
        'timeout'   => 10,
    ],
    'S2' => [
        'host'      => 'myRemoteIP',
        'username'  => 'myRemoteUser',
        'port'      => '2222',
        'password'  => '',
        'key'       => '',
        'keytext'   => '',
        'keyphrase' => '',
        'agent'     => '',
        'timeout'   => 30,
        'directory' => '/home/myRemoteUser/'
    ]

Try 1

SSH::into('S2')->run(['mkdir imAtestDirectory']);

Each time I tried to use SSH::into('S2') I'm getting an Unable to connect to remote server RuntimeException.

I tried without any SSH key, with my private/public SSH key in the keytext field but I'm still getting the same error.

I tried to put the path to my keys in the key field, but it says the file ~/.ssh/mykey doesn't exist.

Moving my keys to another place isn't working either, I'm getting the Unable to connect to remote server again.

Try 2

SSH::into('S1')->run(['ssh -tt -p 2222 myRemoteUser@myRemoteIp', 'mkdir testDir'])

I tried to reproduce exactly what I was doing in command line because I know that can work. I feel like I'm connecting to S2, when I'm looking at what the SSH command is returning I'm getting [...] The programs included with the Debian GNU/Linux system are free software [...] which is the same message I'm getting when I'm doing the command in command line , but it's not creating the folder.


Help me, please

I'm running out of ideas, I've been googling for hours but I can't find how to resolve my problem or any other way of doing what I want to do what I want.

If you need any more precision, feel free to ask.



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2NvDzAk
via IFTTT