Hey guys i am new to laravel and i am trying to build a college project. In the signup part i am not able to validate the users password and email. If the credentials are correct it redirects me to previous page just as i want. But if the credentials are wrong then it is not redirecting me to home page but the page just reloads.
Validation function:
public function user_register(Request $request){
$res = false;
$request->validate([
"name"=>"required",
"email"=>"required|email|unique:custom__auths",
"password"=>"required|min:5|max:12"
]);
$user = new Custom_Auth();
$user->name=$request->name;
$user->email=$request->email;
$user->pasword=$request->password;
$res = $user->save();
echo $res;
if($res==1){
return back()->with('success','you have registered successfully');
}
else{
return redirect('/');
}
}
table in database:
public function up()
{
Schema::create('custom__auths', function (Blueprint $table) {
$table->id();
$table->string("name");
$table->string("email")->unique();
$table->string("password");
$table->timestamps();
});
}
Signup view:
#extends('Layouts.Master')
#section('content')
<link rel="stylesheet" href="{{asset('/Assets/CSS/Auth.css')}}">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<div class="container">
<input type="checkbox" id="flip">
<div class="cover">
<div class="front">
<img class="backImg" src="https://cdn.pixabay.com/photo/2018/01/31/07/36/sunset-3120484_960_720.jpg" alt="">
<div class="text">
<span class="text-1">Helping you grow<br> stronger each day</span>
<span class="text-2">Let's code together</span>
</div>
</div>
<div class="back">
<img class="backImg" src="https://cdn.pixabay.com/photo/2018/01/31/07/36/sunset-3120484_960_720.jpg" alt="">
<div class="text">
<span class="text-1">Complete miles of journey <br> with one step</span>
<span class="text-2">Let's get started</span>
</div>
</div>
</div>
<div class="forms">
<div class="form-content">
<div class="signup-form" >
<div class="title">Signup</div>
<form action="{{route('UserAuth')}}" method="post">
#csrf
<div class="input-boxes">
<div class="input-box">
<i class="fas fa-user"></i>
<input name="name" type="text" placeholder="Enter your name" required>
</div>
<div class="input-box">
<i class="fas fa-envelope"></i>
<input name="email" type="email" placeholder="Enter your email" required>
</div>
<div class="input-box">
<i class="fas fa-lock"></i>
<input name="password" type="password" placeholder="Enter your password" required>
</div>
<div class="button input-box">
<input type="submit" value="Sumbit">
</div>
<div class="text sign-up-text">Already have an account? Login now</div>
</div>
</form>
</div>
</div>
</div>
</div>
#endsection
I tried to use dd to understand the root cause of problem but unfortunately i am not able to get to the root cause of the problem. Any help will be greatly appreciated !!
I think that "page reloads" means validation failed but you didn't show the error messages.
From Laravel docs, what happens if $request->validate() fails:
"If validation fails during a traditional HTTP request, a redirect response to the previous URL will be generated."
So it automatically redirects back, exactly what you're saying - "page reloads".
I assume you just don't show the validation errors.
Again, from the same docs, example how to show them:
#if ($errors->any())
<div class="alert alert-danger">
<ul>
#foreach ($errors->all() as $error)
<li>{{ $error }}</li>
#endforeach
</ul>
</div>
#endif
The $errors variable will automatically be filled from the session.
Related
I tried to let the user enter his ID to display the payment recode
I have two model
Customer, payment which has one to many relations
here is my form
<form action= "{{url('/Check')}}" method="POST" enctype="multipart/from-data">
#csrf
<div class="row gtr-uniform">
<h3>Please Enter youe National ID</h3>
<div class="col-6 col-12-xsmall">
<input type="text" name="cust_id" id="cust_id" value="" placeholder="ID" required/>
</div>
<!-- Break -->
<div class="col-6 col-12-xsmall">
<ul class="actions">
<li><input type="submit" id="btnclaim" value="Search" class="primary" /></li>
<li><input type="reset" value="Reset" /></li>
</ul>
</div>
</div>
</form>
this is the route statement
Route::post('/Check',[paymetController::class,'Check']);
and here is the controller
public function Check(Request $request){
$cust_id=$request->CustomerID;
$pay=Customer::with('payment')->find($cust_id);
return view('DisplayPay',compact('pay'));
}
when I submit the form I got
419 PAGE EXPIRED
i am using localization on my website. the localization is correctly working on one page. when we are redirecting to some other page the page is loading with the language that we selected on the previous page. and we are changing the language on the current page i got an error " page not found ". Why this error is loading.
here the url is changing to http://127.0.0.1:8000/localisation/lang/mal. i need http://127.0.0.1:8000/localisation/create
layout.mainaster.blade.php
<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- CSRF Token -->
<meta name="csrf-token" content="{{ csrf_token() }}">
<title>{{ config('app.name', 'Laravel') }}</title>
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
</head>
<body>
<div id="app">
<div style="background-color: #f8f9fa;">
<nav class="navbar navbar-expand-lg navbar-light bg-light container">
<a href="https://www.mynotepaper.com/" target="_blank"><img src="https://i.imgur.com/hHZjfUq.png"
width="140px;"></a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarTogglerDemo02"
aria-controls="navbarTogglerDemo02" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarTogglerDemo02">
<!-- Right Side Of Navbar -->
<ul class="navbar-nav ml-auto">
<!-- Authentication Links -->
#php $locale = session()->get('locale'); #endphp
<li class="nav-item dropdown">
<a id="navbarDropdown" class="nav-link dropdown-toggle" href="#" role="button"
data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" v-pre>
#switch($locale)
#case('us')
<img src="{{asset('img/us.png')}}"> English
#break
#case('mal')
Mlayalam
#break
#case('in')
Hindi
#break
#default
English
#endswitch
<span class="caret"></span>
</a>
<div class="dropdown-menu dropdown-menu-right" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="lang/en"> English</a>
<a class="dropdown-item" href="lang/mal"> Mlayalam</a>
<a class="dropdown-item" href="lang/in"> Hindi</a>
</div>
</li>
</ul>
</div>
</nav>
</div>
<main class="py-4">
#yield('content')
</main>
</div>
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
</body>
</html>
controller
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App;
use App\Localization;
class LocalizationController extends Controller
{
//
public function index1($locale)
{
App::setLocale($locale);
// store the locale in session so that the middleware can register it
session()->put('locale', $locale);
return redirect()->back();
}
public function index()
{
$data=Localization::get();
return view('localisation.index',[
'localizationdata' =>$data
]);
}
public function create()
{
return view('localisation.create');
}
}
?>
model:
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class Localization extends Model
{
//
use SoftDeletes;
protected $table = 'demo';
protected $primaryKey = 'id';
public $timestamps = true;
protected $dates = ['deleted_at'];
}
create.blade.php
#extends('layouts.mainmaster')
#section('content')
<div class="row">
<div class="col-lg-12">
<form role="form" action="{{action('LocalizationController#store')}}" method="post" enctype="multipart/form-data">
{{ csrf_field() }}
<!-- START card-->
<div class="card card-default">
<div class="card-header">
<div class="card-title">Create</div>
</div>
<div class="card-body">
<fieldset>
<div class="form-group row">
<label class="col-md-2 col-form-label">{{ __('create.name')}}</label>
<div class="col-md-6">
<input type="text" class="form-control" required="required" name="name" placeholder="{{ __('create.name')}}">
</div>
#if ($errors->has('name'))
<span class="invalid-feedback" role="alert">
<strong>{{ $errors->first('name') }}</strong>
</span>
#endif
</div>
</fieldset>
<fieldset>
<div class="form-group row">
<label class="col-md-2 col-form-label">{{ __('create.ph')}}</label>
<div class="col-md-6">
<input type="text" class="form-control" required="required" name="ph" placeholder="{{ __('create.ph')}}">
</div>
#if ($errors->has('ph'))
<span class="invalid-feedback" role="alert">
<strong>{{ $errors->first('ph') }}</strong>
</span>
#endif
</div>
</fieldset>
<fieldset>
<div class="form-group row">
<label class="col-md-2 col-form-label">{{ __('create.address')}}</label>
<div class="col-md-6">
<input type="text" class="form-control" required="required" name="address" placeholder="{{ __('create.address')}}">
</div>
#if ($errors->has('address'))
<span class="invalid-feedback" role="alert">
<strong>{{ $errors->first('address') }}</strong>
</span>
#endif
</div>
</fieldset>
<fieldset>
<div class="form-group row">
<label class="col-md-2 col-form-label">{{ __('create.email')}}</label>
<div class="col-md-6">
<input type="text" class="form-control" required="required" name="email" placeholder="{{ __('create.email')}}">
</div>
#if ($errors->has('email'))
<span class="invalid-feedback" role="alert">
<strong>{{ $errors->first('email') }}</strong>
</span>
#endif
</div>
</fieldset>
</div>
<div class="card-footer text-center"><button class="btn btn-info" type="submit" value="submit">Create</button>
</div>
</div><!-- END card-->
</form>
</div>
</div><!-- END row-->
#endsection
middlewear:
<?php
namespace App\Http\Middleware;
use App;
use Closure;
class Localization
{
/**
* Handle an incoming request.
*
* #param \Illuminate\Http\Request $request
* #param \Closure $next
* #return mixed
*/
public function handle($request, Closure $next)
{
if (session()->has('locale')) {
App::setLocale(session()->get('locale'));
}
return $next($request);
}
}
Route:
Route::get('lang/{locale}', 'LocalizationController#index1');
Route::resource('localisation','LocalizationController');
Little bit late for this response but may help someone else. Just need to change your route and update your view.
In your routes, update your route to:
Route::get('lang/{locale}', ['as' => 'lang.locale', 'uses' => 'LocalizationController#index1']);
In your view you need to change to update the route to actually engage the controller.
So in view update it to;
<div class="dropdown-menu dropdown-menu-right" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="{{ route ('lang.locale', 'en') }}"> English</a>
<a class="dropdown-item" href="{{ route ('lang.locale', 'mal') }}"> Mlayalam</a>
<a class="dropdown-item" href="{{ route ('lang.locale', 'in') }}"> Hindi</a>
</div>
i am new to Laravel , in my project i want to add a comment in the blog after the authentification , i use session with this , so the problem is he don't show the name of the user !
this is my controller comment :
public function store (blog $getid , Request $request)
{
$patient_id=$request->session()->get('patient_id');
comment::create([
'body' =>request('body'),
'blog_id'=> $getid->id,
'patient_id'=>$patient_id
]);
return back();
}
This is the show.blade.php :
#foreach ($showme->comments as $comment)
<blockquote class="blockquote mb-0">
<p style="font-size:15px;">{{$comment->body}}</p>
<p> {{$comment->patient_id}}</p>
<footer class="blockquote-footer"> {{$comment->created_at}} <cite title="Source Title"> </cite></footer>
</blockquote>
#endforeach
</div>
<!-- si le patient est connceter -->
#if(Session::has('log_in'))
<div class="card-block">
<form method="POST" action="/blog/{{$showme->id}}/store" >
#csrf
<div class="form-group">
<label> Commentaire </label> </br>
<textarea name="body" rows="3" cols="80" cols="form-control"></textarea> </br>
</div><div class="form-group">
<button type="submit" class="btn btn-primary"> Ajouter commentaire</button>
</div>
</form>
</div>
#endif
WEB.PHP
Route::Post('/store' , 'patientcontroller#store');
Thank you so much
I have a form like this in my footer:
<div id="footer">
#if(Session::has('newsletter'))
<div class="alert alert-success hidden" id="newsletterSuccess">
<strong>Gelukt!</strong> U bent toegevoegd aan onze email lijst.
</div>
#endif
<form id="newsletterForm" action="/newsletter" method="POST">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<div class="input-group">
<input class="form-control" placeholder="Email adres" name="newsletterEmail" id="newsletterEmail" type="text">
<span class="input-group-btn">
<button class="btn btn-default" type="submit">Go!</button>
</span>
</div>
</form>
</div>
In my function in my controller I have:
public function index(Request $request)
{
Mail::to('info#mydomain.be')->send(new News($request->all()));
return redirect()->to(app('url')->previous(). '#footer')->with('newsletter', 'sent');
}
It redirects back to my previous page and to the correct anchor but it doesn't show my message. I've also tried this:
return Redirect::to(URL::previous() . "#footer")->with('newsletter', 'sent');
But also not working.
You have a "hidden" class in your alert. try removing it.
<div class="alert alert-success hidden" id="newsletterSuccess">
<strong>Gelukt!</strong> U bent toegevoegd aan onze email lijst.
</div>
You should try this:
return redirect()->back()->withInput()->withFlashSucess("Your message");
OR
return Redirect::to('your route',#footer')->withFlashSuccess("Your message");
View file
#if(Session::has('newsletter'))
<div class="alert-success" id="newsletterSuccess">
<strong>Gelukt!</strong> U bent toegevoegd aan onze email lijst.
</div>
#endif
I'm using a request validation to validate my form post which works fine for a "simple" contact class but not for my posts class.
Working:
ContractController GET:
public function showForm()
{
return view('contact');
}
ContractController POST:
public function sendContactInfo(ContactRequest $request)
{
blabla
return back()
->withSuccess("Thank you");
}
not working:
postcontroller GET:
public function changepost($postid)
{
$postdetail = posts::find($postid);
blabla
return view('changepost')->with("postdetail", $postdetail);
}
postcontroller POST:
public function changepostvalues(changepostreqeust $request)
{
blabla
return back()->withSuccess("Thank you");
}
withSuccess and withError is only stored for the next request, correct?
I've also tried to use Session:flash with the same result, success and error are not in the session.
when I try Session::put all work fine. however I don't want to store the messeage permanently in the session and I also want to understand why the infromations are lost...
I believe it has something to do with the return view('changepost')->with("postdetail", $postdetail); where I need to pass also the error and success messages....
Thanks.
EDIT
Add View
#extends('master')
#section('title', 'lala')
#section('sidebar')
#parent
#endsection
#section('page-script')
<link href="{{ asset('/packages/dropzone/dropzoneaddpost.css') }}" rel="stylesheet">
#foreach($images as $image)
<meta name="postimage" content="{{$image->image_path}}" id="{{$image->id}}">
#endforeach
#stop
#section('content')
<div align="center">
<div class="addpost">
#if (Session::has('success'))
<div class="alert alert-info">{{ Session::get('success') }}</div>
#endif
<div class="row">
<div class="files" id="previews">
<div id="template" class="file-row">
<!-- This is used as the file preview template -->
<div>
<span class="preview"><img data-dz-thumbnail /></span>
</div>
<div>
<strong class="error text-danger" data-dz-errormessage></strong>
</div>
<div style="text-align: center;">
<button data-dz-remove class="btn delete mydelbutton">
<i class="glyphicon glyphicon-trash"></i>
</button>
</div>
</div>
</div>
</div>
<div class="row">
<form action="/changepost" method="post">
<div class="form-group">
<label for="txttitle">Titel:</label>
<input class="form-control" id="txttitle" type="text" name="beschreibung" id="beschreibung" maxlength="45" style="" value='{{ $postdetail->beschreibung }}'>
<label for="txtmessage">Beschreibung:</label>
<textarea id="txtmessage" class="form-control" rows="5" name="description" id="description" maxlength="500">{{$postdetail->text}}</textarea>
</div>
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<input type="hidden" name="postid" value="{{ $postdetail->id }}">
<button id="savepost" class="btn mybutton start">
<i class="glyphicon glyphicon-upload"></i>
<span>Save</span>
</button>
</form>
</div>
</div>
</div>
</div>
<script src="{{ asset('/packages/dropzone/dropzone.js') }}"></script>
<script src="{{ asset('/packages/dropzone/dropzone-config.js') }}"></script>
#stop