vendredi 1 juin 2018

Laravel 5 retrieve user email from resetpasswordlog through hashed token

I want to get the record from resetpasswordlog (Note, I have changed the table name) table in Laravel 5.5 through the generated token during forgot password. I do not wan to use the default notification and instead send email to users. I used Hash::make($token) but this is not matched with any record in the "resetpasswordlog" table.

// user model
public function sendPasswordResetNotification($token)
{
dd(Hash::make($token));
}

The result is:

$2y$10$sBeJOd33E7A10ZSwvVZpFeqNe/Cka2jYLdp4rI8fwIkgIFoJZgY5S

But in the db table, I saw the record is entered as like:

$2y$10$v1BM7EE4Xs64Xlv8Cktz/OHpwS/KX0qpMjg4Jf.VuPg...



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

join a table in two columns due to polymorphic relation

I have the following structure:

Buro->hasOne->Address->hasOne->City->hasOne->State Buro->hasOne->Category

and

Order->hasOne->Address->hasOne->City->hasOne->State Order->hasOne->Category

and

Category->hasMany->Orders and Category->hasMany->Buros

I have a "One-To-Many" polymorphic relation between addresses in one side and Buro/Orders in the other side. There is just One address for a buro and just one adddress for an order, therefor I couls use [0] to get the first the first and only one element in a collection.

Address class

class Address extends Model
{
...

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

Büro class

class Buro extends Model
{
....
    public function addressable()
    {
        return $this->morphMany('App\Address', 'addressable');
    }
...
}

Order class

class order extends Model
{
....
    public function addressable()
    {
        return $this->morphMany('App\Address', 'addressable');
    }
...
}

Now I am building a form in the frontend with a SELECT field in order to select just from the Buros that operate in the same State where the order was placed.

Using ELOQUENT I did this:

$all_bueros = Buero::where('category_id', $order->category_id)
                    ->where('title', $order->client->addressable[0]->city->state->title) // <- Look at this "title" column name
                    ->pluck('title', 'id')->all();

The problem here is that the "Title" column name is not in "Buros" table but three tables away. Exactly in: buros.addresses.city.state.title

I have tried these syntaxes but no one worked:

->where('buros.addresses.city.state.title', $order->client->addressable[0]->city->state->title)   // as object notation

and

->where('buros->addressable[0]->cities->state->title', $order->client->addressable[0]->city->state->title)  // using the relation

I used the query builder but there is even more messy:

$buros = DB::table('buros')
                    ->join('categories', 'categories.id', '=', $order->category_id)
                    ->join('addresses', 'addresses.addressable_id', '=', $order->id, 'AND','addresses', 'addresses.addressable_type', '=', 'buros') //two points to join the table
                    ->join('cities', 'addresses.city_id', '=', 'cities.id')
                    ->join('states', 'cities.states', '=', 'states.id')
                    ->select('buros.title', 'buros.id')
                    ->where('states.title', '=', $order->client->addressable[0]->city->states->title)
                    ->get();

My problem is how to join a table in two points since there is a polymorphic relation. Because I need to join the Address Table in the "Buro-column" (addressable_type) and in the Buro-id column (addressable_id)

Any help will be appretiate



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

Package/command to generate lang files in Laravel 5.6

I am building a multilingual laravel 5.6 application and I have a ton of translation keys across my project defined both using @lang blade directive and trans() function.

I wish to find a way (command / package) that would allow me to scan the project for keys and generate files with the respective namespaces. I have found a package that would generate the files for keys like this:

trans('namespace.translation-string')

But I also need to support multiple level namespaces like this i.e. that it would automatically generate the nested namespace folders under each of the system's languages:

trans('namespace.another-namespace.translation-string')



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

Laravel 5.6 - Pass additional parameters to API Resource?

An API Resource can be either a single resource or a collection. In some cases, additional parameters are required to be passed to the resource/collection from the controller. Below is a simple example demonstrating the issue using User as a single/collection resource, and a custom $apple parameter to be passed to the resource for output. The issue can be seen in the final Output (Collection) below, where for the fruit value, we get an incorrect value of banana for the first user, instead of the correct apple value (which all other users get). It works perfectly for the single output, just not the collection. See below:

Controller with UserResource (Single)

$user = User::first();
return new UserResource($user, $apple = true); // $apple param passed

Controller with UserResource (Collection)

$users = User::limit(3)->get();
return UserResource::collection($users, $apple = true); // $apple param passed

UserResource

<?php

namespace App\Http\Resources;
use Illuminate\Http\Resources\Json\JsonResource;

class UserResource extends JsonResource {
    private $apple;

    public function __construct($resource, $apple = false) {
        // Ensure we call the parent constructor
        parent::__construct($resource);
        $this->resource = $resource;
        $this->apple = $apple; // $apple param passed
    }

    public function toArray($request) {
        return [
            'id'     => (int) $this->id, 
            'name'   => $this->name,
            'fruit'  => $this->apple ? 'apple' : 'banana',
        ];
    }
}

Output (Single)

{
    "data": {
        "id": 1,
        "name": "Peter",
        "fruit": "apple" // correct param!
    }
}

Output (Collection)

{
    "data": [
        {
            "id": 1,
            "name": "Peter",
            "fruit": "banana" // INCORRECT param!
        },
        {
            "id": 2,
            "name": "Lois",
            "fruit": "apple" // correct param!
        },
        {
            "id": 3,
            "name": "Brian",
            "fruit": "apple" // correct param!
        }
    ]
}

How can we fix this?



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

Laravel 5.6 The page has expired due to inactivity token is present

Same question already has been ask here, and I have tried everything read.

My old question reference Laravel 5.5 The page has expired due to inactivity token is present

I have tried: "The page has expired due to inactivity" - Laravel 5.5 https://www.5balloons.info/fixed-page-expired-due-inactivity-laravel-5/

I have tried file and database both for cache and session, all of my forms has TOKEN.

Permissions on storage

 drwxrwxrwx  5 ABC ABC   4096 May 30 23:16 storage

My .env file

APP_NAME="Name"
APP_ENV=staging
APP_KEY=SOMEKEY
APP_DEBUG=false
APP_LOG_LEVEL=false
APP_URL=http://url

DB_CONNECTION=mysql
DB_HOST=mysql.host.com
DB_PORT=3306
DB_DATABASE=db_name
DB_USERNAME=db_user
DB_PASSWORD=db_user_password

BROADCAST_DRIVER=log
CACHE_DRIVER=database
SESSION_DRIVER=database
QUEUE_DRIVER=sync

Form

<form class="form-horizontal" method="POST" action="">
        

        <div class="form-group">

            <div class="col-md-12">
                <label for="email" class="control-label">E-Mail Address</label>
                <input id="email" type="email" class="form-control" name="email" value="" required autofocus>

                @if ($errors->has('email'))
                    <span class="help-block">
                                    <strong></strong>
                                </span>
                @endif
            </div>
        </div>

What am I missing here, no idea.



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

URI based routing in nginx

I want to direct example.com/1.0 to one laravel application and example.com/1.1 to another laravel application. If example.com is given, it should by default be redirected to example.com/1.1. I am using nginx as the web server. The location blocks in the configuration look as shown below.

location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
include fastcgi_params;
fastcgi_pass unix:/run/php/php7.1-fpm.sock;
fastcgi_index index.php;
try_files $uri =404;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
limit_req zone=one burst=15 nodelay;

}
location = /50x.html {
root html;
}

The root and index is specified directly in the 443 server block and not inside another location block for /.

How can this be achieved? Any suggestions would be greatly appreciated.



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

upload file in other project directory in laravel

I have a solution file that consist of two different projects. In one of the projects i have a code to upload the file and save it.

Currently the file is saved in same project directory that consist of code to upload the file.

I want to upload the file in other project directory. Both project are same server

Is it possible.



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