RESOLVED: Laravel - Can't make "submit form" route to show up - laravel

RESOLVED!
I just needed to access "links.test/submit" instead of simply "links.test", as "submit.blade.php" was a new page.
I also learned the tutorial uses an older version of Laravel, meaning "resources/views/layouts/app.blade.php" was not created because the
php artisan make:auth
command did not work. For Laravel 7, as Gustavo Alves pointed out, I needed to use these two commands instead:
composer require laravel/ui
php artisan ui vue --auth
ORIGINAL QUESTION:
I am going through a Laravel tutorial for beginners - https://laravel-news.com/your-first-laravel-application. I came to the "Displaying the Link Submission Form" section and pasted the provided code snippet into the routes/web.php file, then created submit.blade.php template at resources/views/submit.blade.php with the provided code snippet, as per instructions.
However, the submit form is NOT showing up in my "links.test".
web.php:
?php
use Illuminate\Support\Facades\Route;
Route::get('/', function () {
$links = \App\Link::all();
return view('welcome', ['links' => $links]);
});
Route::get('/submit', function () {
return view('submit');
});
submit.blade.php:
#extends('layouts.app')
#section('content')
<div class="container">
<div>
<h1>Submit a Link </h1>
<form action="/submit" method="post" >
#if ($errors->any())
<div class="alert alert-danger" role="alert">
Plese fix the following errors
</div>
#endif
{!!csrf_field()!!}
<div class="form-group{{ $errors->has('title') ? 'has-error' : ''}}">
<label for="title">Title</label>
<input type="text" class="form-control" id="title" name="title" placeholder="Title" value="{{ old('title') }}">
#if($errors->has('title'))
<div class="alert alert-danger">
{{ $errors->first('title') }}
</div>
#endif
</div>
<div class="form-group{{ $errors->has('url') ? ' has-error' : '' }}">
<label for="url">Url</label>
<input type="text" class="form-control" id="url" name="url" placeholder="URL" value="{{ old('url') }}">
#if($errors->has('url'))
<span>
<div class="alert alert-danger">
{{ $errors->first('url') }}
</div>
</span>
#endif
</div>
<div class="form-group{{ $errors->has('description') ? ' has-error' : '' }}">
<label for="description">Description</label>
<textarea class="form-control" id="description" name="description" placeholder="description">{{ old('description') }}</textarea>
#if($errors->has('description'))
<div class="alert alert-danger">
{{ $errors->first('description') }}
</div>
#endif
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
</div>
</div>
#endsection

So, what I can gather for your comment is
you need to create resources\views\layouts\app.blade.php where you will have something like this
<!DOCTYPE html>
<html lang="en">
<head>
<title>Your App</title>
#section('head')
<!-- Styles -->
<link href="{{ mix('css/app.css') }}" rel="stylesheet">
#show()
</head>
<body>
#yield('content')
#section('scripts')
<script src="{{ mix('/js/app.js') }}"></script>
#show
#endsection
</body>
</html>
Once you got this you should be able to extend and this should work as well.

Related

Laravel credential validation not working

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.

Laravel login does nothing

I am using Laravel 6 and my login doesn't work.
I started with php artisan make:auth and tested the login. It worked. Then I made a custom login page. My problem is that my custom login page doesn't work. When I click login it just reloads the page without doing anything. Can I debug it somehow? Here is my code of login.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', 'CMS Buddy') }}</title>
<!-- Scripts -->
<script src="{{ asset('js/app.js') }}"></script>
<!-- Fonts -->
<link rel="dns-prefetch" href="//fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css?family=Nunito" rel="stylesheet" type="text/css">
<!-- Styles -->
<link href="{{ asset('css/app.css') }}" rel="stylesheet">
<script src="https://kit.fontawesome.com/fd2bd3b3b6.js" crossorigin="anonymous"></script>
</head>
<body>
<div class="limiter">
<div class="container-login100" style="background-image: url('img/background_login.jpg');">
<div class="wrap-login100 p-t-190 p-b-30">
<form class="login100-form validate-form" method="POST" action="{{ route('login') }}">
#csrf
<div class="login100-form-avatar">
<img src="img/logo.png" alt="Logo">
</div>
<span class="login100-form-title p-t-20 p-b-45">
CMS Buddy
</span>
<div class="wrap-input100 validate-input m-b-10 {{ $errors->has('email') ? ' is-invalid': '' }}"
data-validate="E-Mail address is required">
<input class="input100" type="text" name="email" placeholder="{{ __('E-Mail Address') }}">
<span class="focus-input100"></span>
<span class="symbol-input100">
<i class="fa fa-user"></i>
</span>
#if ($errors->has('email'))
<span class="invalid-feedback" role="alert">
<strong>{{ $errors->first('email') }}</strong>
</span>
#endif
</div>
<div class="wrap-input100 validate-input m-b-10" data-validate="Password is required">
<input class="input100" type="password" name="{{ __('Password') }}"
placeholder="{{ __('Password') }}">
<span class="focus-input100"></span>
<span class="symbol-input100">
<i class="fa fa-lock"></i>
</span>
#if ($errors->has('password'))
<span class="invalid-feedback" role="alert">
<strong>{{ $errors->first('password') }}</strong>
</span>
#endif
</div>
<div class="container-login100-form-btn p-t-10">
<button type="submit" class="login100-form-btn">
{{ __('Login') }}
</button>
</div>
<div class="text-center w-full p-t-25 p-b-230">
#if (Route::has('password.request'))
<a class="txt1" href="{{ route('password.request') }}">
{{ __('Forgot Your Password?') }}
</a>
#endif
</div>
</form>
</div>
</div>
</div>
<script src="{{ asset('js/login/select2.min.js') }}"></script>
<script src="{{ asset('js/login/main.js') }}"></script>
</body>
</html>
I think your password cause these. The validation will return probably "The password field is required".
Mispelled capital "P" for password name attribute.
Change these:
<input class="input100" type="password" name="{{ __('Password') }}" placeholder="{{ __('Password') }}">
To these:
<input class="input100" type="password" name="{{ __('password') }}" placeholder="{{ __('Password') }}">
The page doesn't reload, it's redirecting back for failed validation....
Why?
Because you're missing the password field in your form
Change
name="{{ __('Password') }}"
to
name="password"
The __() function is useful to localize or translate text for your users, however the name attribute is not rendered* in the browser so it doesn't need to be localized..
Laravel expects the form to post email and password

How Can i import Code ckeditor in my laravel app?

I am making a discussion forum application in Laravel . Here I want to use Ckeditor in comment sections. When somebody comments, then the code should show like here in stackoverflow.
#if(Auth::check()!=null)
<div class="col-md-6 col-md-offset-3">
<div class="panel panel-default">
<div class="panel panel-body">
<form action="/comment" method="POST">
{{ csrf_field() }}
<input type="hidden" name="user_id" value="{{ Auth::user()->id }}">
<input type="hidden" name="post_id" value="{{ $post->id }}">
<div class="form-group">
<label for="comment">Reply</label>
<textarea name="body" class="form-control" style="size: 200px"></textarea>
</div>
<input type="submit" name="com" id="com" class="btn btn-xs btn-success pull-right">
</form>
</div>
</div>
</div>
#endif
Please give me very simple steps to use ckeditor. My master file is layout.app and this file is comment.blade.php. Please guide me where I should enter what files and scripts files.
You can use laravel CKEditor Package;
How to install:
Set up package
composer require unisharp/laravel-ckeditor
Add ServiceProvider
Edit config/app.php, add the following file to Application Service Providers section.
Unisharp\Ckeditor\ServiceProvider::class,
Publish the resources
php artisan vendor:publish --tag=ckeditor
Usage
Default way (initiate by name or id) :
<script src="/vendor/unisharp/laravel-ckeditor/ckeditor.js"></script>
<script>
CKEDITOR.replace( 'article-ckeditor' );
</script>
Or if you want to initiate by jQuery selector :
<script src="/vendor/unisharp/laravel-ckeditor/ckeditor.js"></script>
<script src="/vendor/unisharp/laravel-ckeditor/adapters/jquery.js"></script>
<script>
$('textarea').ckeditor();
// $('.textarea').ckeditor(); // if class is prefered.
</script>
github link for more
Example:
#if(Auth::check()!=null)
<div class="col-md-6 col-md-offset-3">
<div class="panel panel-default">
<div class="panel panel-body">
<form action="/comment" method="POST">
{{ csrf_field() }}
<input type="hidden" name="user_id" value="{{ Auth::user()->id }}">
<input type="hidden" name="post_id" value="{{ $post->id }}">
<div class="form-group">
<label for="comment">Reply</label>
<textarea id="editor1" name="body" class="form-control" style="size: 200px"></textarea>
</div>
<input type="submit" name="com" id="com" class="btn btn-xs btn-success pull-right">
</form>
</div>
</div>
</div>
#endif
<script>
$('.editor1').ckeditor(); // if class is prefered.
</script>
<script src="{{asset('vendor/unisharp/laravel-ckeditor/ckeditor.js')}}"></script>
<script src="{{asset('vendor/unisharp/laravel-ckeditor/adapters/jquery.js')}}"></script>
#section('script')
<script>
$('textarea').ckeditor();
</script>
#endsection
and i have provided editor id

return withSuccess withErrors lost

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

How to make Validation in Laravel 5

I am using Laravel 5. And I am a beginner.
In my OrganisationsController I have a method
public function create()
{
return view('organisations.create');
}
In my routes.php I have
Route::model('organisations', 'Organisation');
Route::resource('organisations', 'OrganisationsController');
In my create.blade.php I have a code like this
<link href="{{ asset('css/style.css') }}" rel="stylesheet">
#extends('app')
#section('content')
<div class="container-fluid">
<div class="row">
<div class="col-md-8 col-md-offset-2">
<div class="panel panel-default">
<div class="panel-heading">Organisation</div>
<div class="panel-body">
#if (count($errors) > 0)
<div class="alert alert-danger">
<strong>Whoops!</strong>
There were some problems with your input.<br><br>
<ul>
#foreach ($errors->all() as $error)
<li>{{ $error }}</li>
#endforeach
</ul>
</div>
#endif
<!--<form class="form-horizontal" role="form" method="POST" action="{{ url('/organisations/store') }}"> -->
<form class="form-horizontal" role="form" method="POST" action="{{ url('/organisations/store') }}" accept-charset="UTF-8">
<input type="hidden" name="_token" value="{{{ csrf_token() }}}">
<div class="form-group">
<label class="col-md-4 control-label">Name</label>
<div class="col-md-6">
<input type="text" class="form-control" name="name" value="{{ old('name') }}">
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">E-Mail</label>
<div class="col-md-6">
<input type="email" class="form-control" name="email" value="{{ old('email') }}">
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
I need to validate email and name field
I don't know where to write a validation. Please suggest a example for this. I am using laravel 5. I have searched so many sites. But I cannot get solution for this. Please tell me where to write validation code.
You should use FormRequest for this:
http://laravel.com/docs/5.0/validation#form-request-validation

Resources