Answer the question
In order to leave comments, you need to log in
How in my case to receive and deduce a variable?
There is a table of posts, I need to get using the model only those that are the user who went to the page for viewing their posts (in the table there is a field in which there is an author). Then pull out separate columns from everything received, for example title, id. And what I got to display in the Blade template.
I myself didn’t do anything and dance as soon as I didn’t, but my experience is still not enough. I catch a lot of bugs. Correcting which I get new ones.
use App\all; // my model posts
...
class DashPosts extends Controller
{
public function index()
{
$data = all::where('postAuthor', '=', Auth::user()->name)->value('id', 'title');
$data = array_only($data, ['id', 'title']);
return view('posts', ['data' => $data]);
}
}
Answer the question
In order to leave comments, you need to log in
The value method takes 1 parameter and returns the value of the column of the first record in the selection. Why he is needed here is not at all clear.
You probably need something like all::where(...)->select("id", "title")->get().
Well, yes, next time post the error code and dump variables, there are no psychics here.
The name all for the post model is confusing.
And in general, read about relationships, all this can be made even easier.
In the browser everything is OK, in the terminal there are crocozyabras. What can be wrong?
Finally learn how to use the search engine for such simple questions!
anvarichn.livejournal.com/43752.html
Switch the encoding of the terminal itself to the desired one, I don’t know what OS you have, for a poppy it’s done like this:
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question