Earlier today I had the exact same problem with Auth::attempt always retuning false. I realized that Auth checks for a hashed password, so by doing so I was able to get it to return true, but now it always does. Even if I type asdadfasdfaf in my form, the if statement loads the page. Any suggestions?
Controller:
class userController extends \BaseController
{
public function login()
{
$user = array(
'username' => Input::get('username'),
'password' => Input::get('password')
);
if(Auth::attempt($user))
{
return Redirect::route('home');
}
else
{
return View::make('login');
}
}
}
Form
{{ Form::open(array('url' => 'home' )) }}
{{ Form::label('username', 'Username: ') }}
{{ Form::text('username') }}
</br>
{{ Form::label('password', 'Password: ') }}
{{ Form::password('password') }}
</br>
{{ Form::submit() }}
{{ Form::close() }}
The Routes file:
Route::post('home', 'userController#login');
No matter what I enter it always directs me to my "home" page?
The action url should be login
{{ Form::open(array('url' => 'login' )) }}
^^^^ as you used Auth::attempt to this URL
{{ Form::label('username', 'Username: ') }}
{{ Form::text('username') }}
</br>
{{ Form::label('password', 'Password: ') }}
{{ Form::password('password') }}
</br>
{{ Form::submit() }}
{{ Form::close() }}
Related
here is my ContactController.php:
public function destroy($id){
$contact = Contact::find($id);
$contact->delete();
return Redirect::to('http://localhost:8000/contactsview');
}
Here is my rountes.php
Route::delete('/contactsview/destroy/{id}', array('uses'=>'ContactController#destroy'));
Here is my index.blade.php:
{{ Form::open(array('url'=>'/contactsview/delete/'.$contact->id, 'method'=>'DELETE', 'style'=>'display:inline;')) }}
<!-- {{ Form::hidden('id', $contact->id) }} -->
{{ Form::submit('Delete') }}
{{ Form::close() }}
What did I do wrong?
Try the form with this instead, passing in the $contact->id as a param rather than directly in the URL:
{{ Form::open(array('method' => 'DELETE', 'action' => array('ContactController#destroy', $contact->id )) }}
I just have a very simple product category creation form in laravel , like so:
{{ Form::open(array('url'=>'admin/category/create')) }}
<p>
{{ Form::label('name') }}
{{ Form::text('name') }}
</p>
{{ Form::submit('Create Category' , array('class'=>'secondary-cart-btn')) }}
{{ Form::close() }}
For the create method i have the following code:
public function postCreate() {
$validator = Validator::make(Input::all() , Category::$rules);
if($validator->passes()) {
$category = new Category;
$category->name = Input::get('name');
$category->save();
return Redirect::to('admin/categories/index')
->with('message' , 'Category created');
}
return Redirect::to('admin/categories/index')
->with('message' , 'something went wrong')
->withError($validator)
->withInput();
}
Now when i click on the submit button, i get the following error:
C:\xampp\htdocs\ecomm\bootstrap\compiled.php
if (!is_null($route)) {
return $route->bind($request);
}
$others = $this->checkForAlternateVerbs($request);
if (count($others) > 0) {
return $this->getOtherMethodsRoute($request, $others);
}
throw new NotFoundHttpException();
}
protected function checkForAlternateVerbs($request)
You can see the error more visvually HERE.
What am i doing wrong ?
Instead of
{{ Form::open(array('url'=>'admin/category/create')) }}
<p>
{{ Form::label('name') }}
{{ Form::text('name') }}
</p>
{{ Form::submit('Create Category' , array('class'=>'secondary-cart-btn')) }}
{{ Form::close() }}
try this:
{{ Form::open(array('route'=>'post.homes')) }}
<p>
{{ Form::label('name') }}
{{ Form::text('name') }}
</p>
{{ Form::submit('Create Category' , array('class'=>'secondary-cart-btn')) }}
{{ Form::close() }}
In routes.php:
Route::post('aboutus', array('as' => 'post.homes', 'uses' => 'HomeController#postContactUs'));
I have the following route entry:
Route::get('admin/user/edit/{id}', 'AdminController#editUser');
And given is controller Method:
public function editUser($id)
{
$user = User::where('id',1);
return View::make('admin.edit_user')
->with('user',$user);
}
All I want to bind model in my edit form which looks like this:
#extends('layouts.admin_master')
#section('content')
<div>
{{ Form::model($user) }}
{{ Form::label('first_name', 'First Name') }}
{{ Form::text('first_name') }}
{{ Form::close() }}
</div>
#stop
I can see text box but value is not being populated. first_name is column in my table users
I was trying to do what mention here
Try this..
public function editUser($id)
{
$user = User::where('id',1)->first();
return View::make('admin.edit_user')
->with('user',$user);
}
#extends('layouts.admin_master')
#section('content')
<div>
{{ Form::model($user) }}
{{ Form::label('first_name', 'First Name') }}
{{ Form::text('first_name',$user->first_name) }}
{{ Form::close() }}
</div>
#stop
sorry if this is a very newbie Q..
but please help me to solve this problem. plus give me the reason about why this error happened..
this is my edit view
new.blade.php
#section('content')
#include('common.show_error')
{{Form::open(array('url'=>'author/update', 'method'=>'PUT'))}}
<p>
{{ Form::label('name', 'Name: ') }}</br>
{{ Form::text('name', $author->name) }}
</p>
<p>
{{ Form::label('bio', 'Biography: ') }}</br>
{{ Form::textarea('bio', $author->bio) }}
</p>
{{ Form::hidden('id', $author->id) }}
<p>{{ Form::submit('Edit Data') }}</p>
#stop
this is my show view
show.blade.php
#extends('layouts.default')
#section('content')
<h1>{{ $author->name }}</h1>
<p>{{ $author->bio }}</p>
<p>{{ $author->updated_at }}</p>
<span>
{{ HTML::linkRoute('authors', 'Home') }} |
{{ HTML::linkRoute('edit_author', 'Edit', array($author->id)) }} |
{{ Form::open(array('url'=>'author/destroy', 'method'=>'DELETE', 'style'=>'display: inline;')) }}
{{ Form::hidden('id', $author->id) }}
{{ Form::submit('Delete') }}
{{ Form::close() }}
</span>
#stop
this is my controller
public function update($id)
{
$id = Input::get('id');
$validator = Member::validate(Input::all());
if($validator->fails()){
return Redirect::route('members.edit', $id)->withErrors($validator);
} else {
Member::where('id','=',$id)->update(array(
'name' => Input::get('name'),
'bio' => Input::get('bio')
));
return Redirect::route('members.show', $id)
->with('message', 'Data Succesfully Updated');
}
}
the case: when I try to edit data using edit button. it said:
"Trying to get property of non-object laravel"
and when I check at the error log. it refers to
<h1>{{ $author->name }}</h1>
public function update($id)
{
$id = Input::get('id');
$validator = Member::validate(Input::all());
if($validator->fails()){
return Redirect::route('members.edit', $id)->withErrors($validator);
} else {
$author = Member::find($id);
$author->update(array(
'name' => Input::get('name'),
'bio' => Input::get('bio')
));
return Redirect::route('members.show', $id)
->with('message', 'Data Succesfully Updated')
->with('author', $author);
}
}
Little changes in your controller, try it :) In your code, you are not send variable "author" into your view.
I encounter a error:
Some mandatory parameters are missing ("users") to generate a URL for route "users.update".
I have this set on my view:
{{ Form::open( array('action' => array('UsersController#update')) ) }}
<div> {{ Form::label('username', 'Username:') }}
{{ Form::text('username', $user->username , array('class' => 'form-control')) }}</div>
<div> {{ Form::label('email', 'Email Address:') }}
{{ Form::text('email', $user->email , array('class' => 'form-control')) }}</div>
<div> {{ Form::label('new_password', 'New Password:') }}
{{ Form::text('new_password', '', array('class' => 'form-control')) }} </div>
<div> {{ Form::label('old_password', 'Old Password:') }}
{{ Form::text('password', '', array('class' => 'form-control')) }} </div>
{{ Form::submit() }}
{{ Form::close() }}
I also have a function in my controller linked to update:
public function update() {
return 'This is an update';
}
And finally, when I check all the routes available in Artisan command, I found that the update has a route to: users/{users}
What's wrong with my codes? I'm trying to update a user and it throws this error.
Your route is defined in a way to expect a variable $users to be passed. because of the: {users}
Instead, you should define it like:
Route::post('users/update', 'UsersController#update');
and then in your function update() get the post variable by:
$users_data = Input::get();
OR
if you want to keep the parameter, redefine the form by passing additional parameter:
{{ Form::open( array('action' => array('UsersController#update', $id)) ) }}
The way you are opening the FORM, it is needs a route paramenter. If you dont want to pass parameters, just use the following:
{{ Form::open(array('action' => 'UsersController#update')) }}
Instead of:
{{ Form::open( array('action' => array('UsersController#update')) ) }}
Even when you're setting a action, you may still need a route for it. I STRONGLY recommend you to always use CLEARED DEFINED routes to your controllers. See if the Resource Controllers helps you, in case you don't wanna to define every god damm route (I DON'T).
And, finally answering your question: I think a
{{ Form::open(array('action' => 'UsersController#update')) }}
...may solve your problem. Hope it helps. Sorry for my bad english! :D