Laravel syntax error in variable while nothing changed - laravel

I am making a mobile app with a username-password login screen. Yesterday i left my computer on when i was done with work. Today i sit behind my computer and try to log in. Strange thing is i get this error:
{"error":{"type":"Symfony\\Component\\Debug\\Exception\\FatalErrorException","message":"syntax error, unexpected '$credentials' (T_VARIABLE)","file":"C:\\Google Drive\\htdocs\\laravel4_test4\\app\\controllers\\MobileController.php","line":18}}
Weirdest thing of all is i haven't chaged any code since yesterday. This is the part of my controller code that seems to give the syntax error.
public function login(){
$input = Input::all()
$credentials = array('username' => $input['name'], 'password' => $input['password']);
if(Auth::attempt($credentials)){
// HERE COMES THE REST
There seems to be nothing wrong with the code. Does anyone know why this could be happening?

You missed a semicolon after $input = Input::all()
$input = Input::all();

Related

Laravel unit-test failing, but working in 'real life'?

I'm working on a new app. Most of my unit-tests work as I expect them to, except one where I'm updating an existing item:
/** #test */
function can_edit_thought()
{
$user = User::factory()->create();
$response = $this->actingAs($user)->post('/submit', [
'thought' => 'My first thought'
]);
$thought_id = $user->thoughts->first()->id;
$response = $this->actingAs($user)->post('/submit', [
'thought' => 'something different',
'thought_id' => "1"
]);
// should get redirected to 'thoughts'
$response
->assertStatus(302)
->assertHeader('Location', url('/thoughts'));
// should still be 1 thought...
$this->assertEquals($user->thoughts->count(), 1);
// the first thought should now containt "different"
$thought = $user->thoughts->first();
//fwrite(STDERR, print_r($user->thoughts, TRUE));
$this->assertTrue(str_contains($thought->thought, "different"));
This last assert fails (and printing the 'thought' also shows it's not changed).
But when I do exactly the same in my app, the changes do happen.
Any ideas? (I'm leaning toward something with authentication, or the fact that test uses lite and real-app uses MySQL)
Found the bug, I needed to do a refresh:
// the first thought should now containt "different"
$thought = $user->thoughts->first();
$thought->refresh();
$this->assertTrue(str_contains($thought->thought, "different"));
(leaving this here for future bug hunters)

Test the view that is showing after authorisation

I am learning how to do simple tests on my application. Simply, I dont know how to get over the problem below.
Problem:
I am just trying to see, if my page is loading correctly by checking if site contain word "Send". Send is my button that is located in my view.
How can I check the view as a logged user?
My test function:
public function testSiteIsLoadingCorrectly()
{
$response = $this->get('/homepage');
$response->assertSee("Send");
}
After some research I got this function:
public function testSiteIsLoadingCorrectly() {
$user = User::factory()->create();
$response = $this->actingAs($user)
->withSession(['banned' => false])
->get('/');
$response->assertSee("Welcome on my page!");
}
It works great but only for "/". If I give another route, my console is showing a lot of text and finally it doesn't work.
How can I solve this?
assertSee() works bad with polish chars like ą,ę,ć etc...
That's the reason of all problems.
PS.
"Send" in Polish means "Wyślij"...

laravel Auth attempt parameters issue

I have the following code:
if(!empty($email) && !empty($password))
{
if (Auth::attempt(array('email' => $email, 'password' => $password, 'activated' => 1)))
{
return Redirect::route('home');
}else{
return Redirect::route('signin')->with('message', 'Login Failed. Please try again.');
}
}else{
return Redirect::route('error');
}
The above is the login function of my application. The login view loads and user enters date and above is executed. Auth::attempt is passed a third parameter above to check if activated field in table is 1. It throws a weird error and this is it:
Please help me understand what is going wrong.
Your app/model/User.php file is missing a closing bracket }. That is what the debug tool is telling you.
Looks like you're just missing a closing } on your function or class.
The error unexpected end means php finished processing the file but something hasn't been closed (php was expecting more), and because it's expecting a function this means the class hasn't been closed.

Symfony 2: session_start causes ERR_EMPTY_RESPONSE

We just moved our Symfony2.3 project to another server and now we encounter the following problem:
The routes /login and _wdt/9d5405 result in a ERR_EMPTY_RESPONSE error in Google Chrome (and all other browsers showing their specific error messages). The error occurs in both, prod and dev environment.
I tracked down the issue from my loginAction
/**
* #Route("/login", name="login")
* #Route("/login/{redirect}", name="login_redirect")
* #Template()
*/
public function loginAction($redirect = '')
{
if ($this->getUser())
{
return $this->redirect($this->generateUrl('crea_frontend_index'));
}
$request = $this->getRequest();
$session = $request->getSession();
// get the login error if there is one
if ($request->attributes->has(SecurityContext::AUTHENTICATION_ERROR))
{
$error = $request->attributes->get(
SecurityContext::AUTHENTICATION_ERROR
);
}
else
{
$error = $session->get(SecurityContext::AUTHENTICATION_ERROR);
$session->remove(SecurityContext::AUTHENTICATION_ERROR);
}
$redirect = urldecode($redirect);
return array(
'last_username' => $session->get(SecurityContext::LAST_USERNAME), // last username entered by the user
'redirect' => $redirect,
'error' => $error,
);
}
This line produces the error:
$error = $session->get(SecurityContext::AUTHENTICATION_ERROR);
And I tracked it down to
Symfony/Component/HttpFoundation/Session/Storage/NativeSessionStorage.php
and there in line 148 if (!session_start()) {.
So it turnes out that session_start at this point produces the error but when I add a session_start(); to app.php and comment everything else it works.
Now I am completely puzzled on how to fix this. Any ideas on how to solve this or just how to further debug would be very appriciated.
PHP 5.4.20
No errors in logfiles
UPDATE
The error seems to be somehow related to these bug discussions:
https://bugs.launchpad.net/ubuntu/+source/php5/+bug/424789
https://bugs.gentoo.org/show_bug.cgi?id=276583
UPDATE
Solved: The Problem was the PHP Version 5.4.20. We tested 5.3.17 and 5.5.9. Both function well. Except 5.4.20. But I still want to know what exaclty causes this error. This could then result in a Symfony fix to deal with this version.

Laravel 4 Email not working

I've been looking for the answer for two days and still nothing. I've followed several tutorials where nothing more than just a few config settings are required, but my Laravel 4 app still doesn't want to send an e-mail. It always throws the same Exception and nobody seems to have the answer. It seems that I've tried everything but the working one.
Route::get('/sendemail', function() {
$data['user'] = 'Test User';
Mail::send('email.test', $data, function($m) {
$m->to('myemail#example.com')->subject('Email test');
});
});
But when I'm in the specified route, it always throws the same error:
Argument 1 passed to Swift_Transport_EsmtpTransport::__construct()
must implement interface Swift_Transport_IoBuffer, none given
The config is ok and even changing the driver from 'smtp' to 'mail' in config/mail.php throws also Exception.
Argument 1 passed to Swift_Transport_MailTransport::__construct() must be an instance of Swift_Transport_MailInvoker, none given
I'm stuck in here and I don't know that to do. My composer is up to date and PHP version is 5.4.4.
Any advice will be much appreciated.
Thank you.
You have probably found an answer by now.
But I think you need a second argument for the to.
Try:
$data = array('user' => $user);
Mail::send('email.test', $data, function($message) use ($user)
{
$message->to($user->email, $user->name)->subject('Email Test');
});

Resources