I have error after error. I found the first answer to my question. I had to include the
use App{model}
Now, I have been stuck again. I'm outraged by the change this Framework has made from 4 => 5. I really enjoyed Laravel 4. and now i'm curing Laravel every second I continue to use it. It has taken me over 8 hours, what I have done in 45 minutes with Mongo, Mongoose, Node, Express. I'm hoping there is light at the end of the tunnel.
** FROM THE DOCS**
Getting All Input For The Request
$input = Request::all();
=> This does NOT work! I have read over 6 posts from stack, here, and blogs to work with the multiple request handlers packaged with Laravel, with no luck at all. I'm forced to once again shake my head at Laravel 5 in disguise. Taylor Otwell - just tell me Why? WHY!!! would you add so much complexity, I feel like i'm working through Java NullPointer errors now.
Try method injection, mate.
If the code below is a mess, I apologise, I've just written it out on my phone.
public function create(Request $request)
{
return dd($request->all());
}
PSR-4 Namespacing introduced with Laravel 5 is a good thing, really, as it gives you much more freedom on how to structure your application. Once you grasped the basics of it, it's not that complex.
To reply your question, in L5 you can use controller method injection to retrieve the input :
(from the doc)
public function store(Request $request)
{
$name = $request->input('name');
//
}
RemiCollin said:
PSR-4 Namespacing introduced with Laravel 5 is a good thing, really, as it gives you much more freedom on how to structure your application. Once you grasped the basics of it, it's not that complex.
To reply your question, in L5 you can use controller method injection to retrieve the input :
(from the doc)
public function store(Request $request) { $name = $request->input('name'); // }
This hasn't worked, I get a blank return on my request. The data is JSON based. I am using the same structure I had for a Laravel 4 application. So I apologize for the frustration coming out, but I think you'll can understand, an upgrade shouldn't force you to rewrite everything from scratch, only modify.
Well, that's strange, what does
dd($request->input()->all() );
Outputs ?
I can understand your frustration, though. My recommandation for this would be build a few new apps using L5, then move your previous applications once you're confortable with. Laravel is a fast moving forward platform, which has it benefits and its drawbacks.
Also watch some of the free laracast videos. I was the same at first, I was used of L4. It did take me a few extra days and a user dberry to understand some of the new stuff. But after you get used of the namespacing, what use statements to use, request, and auth it gets easier. Also the html part is now a separate download through composer. Search forum for this topic.
I >jimgwhit said:
Also watch some of the free laracast videos. I was the same at first, I was used of L4. It did take me a few extra days and a user dberry to understand some of the new stuff. But after you get used of the namespacing, what use statements to use, request, and auth it gets easier. Also the html part is now a separate download through composer. Search forum for this topic.
I am really just using Laravel as my backend, because I loved some of the capacity that I could iterate.
I'm in the same condition, I used L4 and now i'm trying to switch to L5 but with a lot of difficult. The namaspace is the first, the new directory structure is the second. I hope that in future the workflow will easiest than now, but I'm not sure :(
All that solve this problem would be a good IDE, say Phpstorm, you are gonna love namespace with that.
Any possible solution for the Blank Array I get returned on any request. I try to post an JSON object like so
I just want to return this input. So I have:
public function store(Request $request){
return $request->all();
}
public function store()
{
$input = Input::all();
return Contact::create(array(
'first_name'=>$input['first_name'],
'last_name'=>$input['last_name'],
'email_address'=>$input['email_address'],
'phone_number'=>$input['phone_number'],
'description'=>$input['description']
));
}
Note: Different Application. These were my sample apps that I have to simplify the problem here.
Glad I haven't tried 5 yet! If it ain't broke, don't fix it y'all!
@ezos86 . I tested posting your JSON object. Works for me. If you have a blank array, that probably mean the Content-Type header in your POST request is wrong. Check if it is set to 'application/json'.
Guys, you must know how to use namespaces. It's really powerfull feature. There is a free lesson on laracast: https://laracasts.com/lessons/namespacing-primer
I have to agree that laravel seems like it's getting too complicated. Name spacing is good, but I liked when it was optional. I also liked the directory structure in 4 better. no native form helper kinda stinks too, just another thing I have to install.
Try calling request with \Request
public function store(\Request $request){
return $request->all();
}
RemiCollin said:
@ezos86 . I tested posting your JSON object. Works for me. If you have a blank array, that probably mean the Content-Type header in your POST request is wrong. Check if it is set to 'application/json'.
I noticed this was one thing, along with a few others. I had done too many searched and ended up with some mangled stuff from the beginning.
Thank you.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community