I, имеющий небольшой вопрос с Laravel 5.2Laravel 5,2 Retrieve Аутентифицированный ID пользователя
Я пытаюсь получить аутентификацией идентификатор пользователя и по какой-то причине не работает. Каждый раз, когда у меня есть 0 в моей базе данных, а не действительный идентификатор пользователя ...
В моем контроллере у меня есть Auth, сверху включен.
Мой метод магазин выглядит следующим образом:
public function store(StoreClassifiedRequest $request)
{
$title = $request->input('title');
$category_id = $request->input('category_id');
$description = $request->input('description');
$price = $request->input('price');
$condition = $request->input('condition');
$main_image = $request->file('main_image');
$location = $request->input('location');
$email = $request->input('email');
$phone = $request->input('phone');
$owner_id = Auth::user()->id;
....
// Create command
$command = new StoreClassifiedCommand($title, $category_id, $description, $main_image_filename, $price, $condition, $location, $email, $phone, $owner_id);
$this->dispatch($command);
return \Redirect::route('classifieds.index')->with('message', 'Listing Created');
}
Все вроде бы хорошо, только идентификатор всегда 0 для какой-либо причине после вставки. Я сделал var_dump на Auth :: пользователя() -> идентификатор и я получаю Int (2)
Я действительно ценю любые предложения ...
StoreClassifiedCommand.php:
<?php
namespace App\Commands;
use App\Commands\Command;
use Illuminate\Contracts\Bus\SelfHandling;
use App\Classified;
class StoreClassifiedCommand extends Command implements SelfHandling {
public $title;
public $category_id;
public $description;
public $main_image;
public $price;
public $condition;
public $location;
public $email;
public $phone;
public $owner_id;
// Create a new command instance
public function __construct($title, $category_id, $description, $main_image, $price, $condition, $location, $email, $phone, $owner_id)
{
$this->title = $title;
$this->category_id = $category_id;
$this->description = $description;
$this->main_image = $main_image;
$this->price = $price;
$this->condition = $condition;
$this->location = $location;
$this->email = $email;
$this->phone = $phone;
$this->owner_id = $owner_id;
}
//Execute the command.
public function handle()
{
return Classified::create([
'title' => $this->title,
'category_id' => $this->category_id,
'description' => $this->description,
'main_image' => $this->main_image,
'price' => $this->price,
'condition' => $this->condition,
'location' => $this->location,
'email' => $this->email,
'phone' =>$this->phone,
'owner_id' =>$this->owner_id,
]);
}
}
Пожалуйста, покажите 'StoreClassifiedCommand'. – user2094178
@ user2094178 только что обновил код, включая источник команды. – CyberFountain
является 'owner_id' заполняемым на модели? – lagbox