auth() is not working in controller when coming from vue - laravel

I have a store method in a controller. now for a field, I am inserting auth()->user()->id. when I am submitting the form from a normal blade, it works fine. but when I am submitting the form from a vue component, it is returning 500 error when I am using auth()->user()->id. instead of this, if i write just 4 or 10 or any static data, it is working fine again!

Maybe the id you submit is in an invalid format and your backend script fails on it. Try to see first if you really have the id and not null or undefined. If so, then see if the id is int or string in your js and then finally see what datatype your backend accepts. If this does not work, please provide some code. You can also see your apache log, what error it throws when you try to access your endpoint.

Related

How to stop the GET method is not supported for this route from showing?

I have a working Laravel project with loads of different routes.
I'm currently testing it and one of my tests was to check if a user were to use a delete or post route from the URL. I didn't know what the application would do honestly and it outputted the typical:
The GET method is not supported for this route. Supported methods: DELETE
which I have seen a million times. Is there a way to stop this error from coming up and instead output an error screen or simply redirect to a different view?
The error message:
The GET method is not supported for this route. Supported methods: DELETE.
should only appear when your Laravel site has APP_DEBUG set to true (in the .env file).
When APP_DEBUG is set to false as it should always be in on a live site, then the user will be shown a 404 error page instead.
You can easily test this by adding the following code to your routes file:
Route::delete('test', function() {
return 'You should never see this text when viewing url via a GET request';
});
May be u didn't noticed but ur form tag method attribute and route definition is different

Parameter format issue with ASP.NET Web API controller

I am watching this pluralsight demo video on Web Api, and he is using fiddler to pass in a parameter using Http Get with the syntax of controller/parameter
So he's using http://localhost:2405/api/values/5
5 Is the parameter he's passing in.
In my code, I have everything set up exactly the same way he does... with a routing template of {controller}/{id} and a controller method with a signature of
public string Get(string zipcode)
I can pass a parameter just fine with http://localhost:2405/api/values?zipcode=25252 but if I try passing in a paramter the way he does, like http://localhost:2405/api/values/25252 I get an error saying I do not have an action available to handle that request on the controller.
What is he doing right, that I'm doing wrong?
You need to change your routing template to {controller}/{zipcode} as the name of the parameter must match the name in the template.

PHP Kohana 3.2.2 multipart form $_POST not set on MAC but works on Win

I've just encountered a weird problem. I've recently developed a medium size website using Kohana 3.2.2 + jquery + html + WAMP on Windows 7 platform. And everything seems to be working fine, until someone tries accesing the page from Mac platform. It seems that when sending some data with files in multipart form the global variable $_POST is not set, even though when debugging the data in web browser i'm able to see that DATA IS SET :| it's just not accesable by the controller with any $_POST or request->post(). I'm repeating, everything works perfectly when user is accesing page from Windows platform (tested on few separated clients), but not working when accesing from Mac platforms (tested on few separated clients).
It's killing me...
Example of what im trying to do:
In View:
user puts data into inputs (text and file types). Data is being send by form with enctype = multipart/form-data to controller's action
In controller:
$post = request->post();
if($post['sometextinput'] != '') throws exception of unknown index 'sometextinput'.
That's extremely odd. I use Kohana on a daily basis (I develop on a Mac) and have never had an issue like that. Could you post your controller and the view? I'll plug it into a dummy project and see if I can replicate the issue. If I can I'll do what I can to get it working.
EDIT:
Could it possible be an odd configuration issue?
Just for my own clarification.
You're submitting a form that contains input fields and one or more file uploads.
When viewing it on a Windows machine you can see that the data is set in $_POST or $request->post().
On OSX it's not viewable to the controller via $_POST or $request->post();
In your before method make sure you have "parent::before();". If you are already calling parent::before() try putting it as the first statement in your before() method. If that doesn't work try adding it as the last statement. It's a shot in the dark, but it's worth a try.
If you don't have a before() method then add one and call parent::before();.
I'm not sure if you were just in a hurry to type up your example above but it actually should be:
#$post = request->post(); //wouldn't recommend doing this
if($this->request->post('sometextinput') != '') throws exception of unknown index 'sometextinput'.

CakePHP redirect method not redirecting

I am trying to redirect to a new page using CakePHP redirect method but for some reason the redirect is not working. The code I am using to redirect is
public function update_sticky_postition_in_db()
{
$this->autoRender = false;
... // Save info to database
$this->redirect(array('action' => 'tool'));
}
Where tool is the name of the view I am tring to redirect to. To try and speed the process of finding the problem I have checked few things and think I have found the cause of the problem. Basically I am trying to redirect to the view that is currently active which I think is part of the reason why it is not redirecting. I have read that it might have something to do with caching of the page but I am not sure how to solve that issue.
Also when using firebug I can see the redirect is sending a GET request but after that nothing is happening. Do I have to do something with the GET request or should Cake handle that for me. Also I have checked the URL of the GET and it is correct.
It is located within the controller with the correct name as I can view the original tool page.
Also the update_sticky_postition_in_db() method does not have a view (hence why the auto render is set to false), its intended purpose is to update a row in the database from an ajax call.
From your post it seems you're firing the update_sticky_postition_in_db() using ajax call, so that the redirection will not work.
You can do redirection using JavaScript within ajax success method.
In order to do that, you may send some json_encode() message from you above method and checking that status within ajax success method you can do a redirect using window.location.

POST request in Windows phone

I am trying to get some data from the user and send it to my server for logging purposes. I was able to do it easily with jquery for my website. When I try to write a windows app for the same I am clueless as to how to post the data to my server.
So far I have fetched the data from the user and I am trying to use OpenWriteAsync function of webclient to send it to my server. I understand how OpenWriteAsync function works but I am not able to figure out how to send my own data.
My php script in my server will get values with name "FILENAME" and "FTIME" like,
$fname = $_POST['FILENAME'];
$time = $_POST['FTIME'];
So I have got this information from the user in two different string variables in c# inside my app. Now how do I send this to my server so that my php script gets this value and logs it inside my server.
I hope I am clear.
Take a look at UploadData method.
The way you use it something like this:
UploadData("http://abc.com","POST", "data in byte array");
Note: you need to convert data to byte array
Reference: http://msdn.microsoft.com/en-us/library/ktfa4fek(v=VS.90).aspx
You can do this by using the ContentType property in the HTTPWebRequest object.

Resources