Laravel 5.4 not registrating users to database, - mysql

I'm simply trying to make my register form submit to my database, but my problem is you enter the info to the form press submit and it just reloads the page and does not send anything to the database.
originally it would submit what i entered but when you went to login it would just reload the page and not redirect, so i changed some stuff one thing lead to another now its not doing anything and i cannot pin-point the problems.
RegisterController.php
namespace App\Http\Controllers\Auth;
use App\Admin;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Validator;
use Illuminate\Foundation\Auth\RegistersUsers;
class RegisterController extends Controller
{
use RegistersUsers;
/**
* Where to redirect users after registration.
*
* #var string
*/
protected $redirectTo = ('index');
/**
* Create a new controller instance.
*
* #return void
*/
public function __construct()
{
$this->middleware('guest:admin');
}
routes/web.php
<?php
Auth::routes();
Route::get('/index', 'HomeController#index');
Route::prefix('/admin')->group(function() {
Route::get('/login', 'Auth\AdminLoginController#showLoginForm')->name('admin.login');
Route::post('/login', 'Auth\AdminLoginController#login')->name('admin.login.submit');
Route::get('/', 'AdminController#index')->name('admin.dashboard');
Route::get('/logout', 'Auth\AdminLoginController#logout')->name('admin.logout');
});
Route::prefix('/admin')->group(function() {
Route::get('register', 'Auth\AdminRegisterController#showRegistrationForm');
Route::post('register', 'Auth\AdminRegisterController#register')->name('admin.register');
});
Route::get('about', function () {
return view('about');
});
Route::get('advertise', function () {
return view('advertise');
});
Route::get('index', function () {
return view('index'); })->middleware('auth');
register.blade.php
#extends('header')
<div id="form-su" style="background-color: #d8b6ff" >
<h3 class="signuph"> Register </h3>
</div>
<form method="POST" action="{{ route('admin.register') }}">
<input type="hidden" name="_token" value="{!! csrf_token() !!}">
#if ($errors->has('name'))
<span class="help-block">
<strong>{{ $errors->first('name') }}</strong>
</span>
#endif
<div class="div-su {{ $errors->has('name') ? ' has-error' : '' }}">
<input class="signup-menu2{{ $errors->has('name') ? ' has-error' : '' }}" " type="text" name="name" value="{{ old('name') }}" placeholder=" Name.." required >
<input class="signup-menu2{{ $errors->has('email') ? ' has-error' : '' }}" " type="email" name="email" value="{{ old('email') }}" placeholder=" Email.." required >
</br>
<input class="signup-menu2{{ $errors->has('password') ? ' has-error' : '' }}" type="password" name="password" placeholder=" Password.." required >
#if ($errors->has('password'))
<span class="help-block">
<strong>{{ $errors->first('password') }}</strong>
</span>
</br>
<label> confirm password
<input class="signup-menu2 " type="password" name="password_confirmation" placeholder=" Confirm Password.." required >
</label>
#endif
</br>
<button class="signup-btn" type="submit" name="submit" value="submit"> Sign Up </button>
</form> </br>
<p class="forgotten-password" href=""> Forgotten password?</p> </br>
<p class="log-in-here" a href="">Log in here </p> </br>
</div>
</div>
</form>
</body>
</html>
also for some reason the confirm password input does not show on the form in the browser, but if you submit the form it pops up... whys that?
i know that you may need to see other pages so don't hesitate to ask for them
i appreciate any help guys,

Related

Textarea with CKEditor not saving html tags on server side

I am using Laravel 8, MySQL, and CKEditor. I would like to ask what could possibly be causing a difference between my local and server.
On my local what I enter into the text editor will be saved to the DB along with the html tags.
While on the server, it will only save the text without the html tags
Below is my controller
public function store(Request $reqst){
$new_info = new Information;
$rules = array(
'title' => ['required', 'string', 'max:255'],
'content' => "required",
);
$this->validate($reqst, $rules);
$new_info->title = $reqst->title;
$new_info->content = $reqst->content;
$new_info->user_id = Auth::user()->id;
$new_info->save();
return redirect('/admin/informations');
}
Here is my blade
<form action="{{ route('informations/add-new-information/store') }}" method="POST" class="col-lg-12 mt-4">
#csrf
<div class="form-group">
<label for="title">Title: <span class="text-danger">*</span></label>
<input type="text" name="title" id="title" class="form-control #error('title') is-invalid #enderror" required placeholder="Maximum of 255 Characters">
#error('title')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</div>
<div class="form-group">
<label for="content">Content: <span class="text-danger">*</span></label>
<textarea name="content" id="content" cols="30" rows="10"></textarea>
</div>
<div class="form-group">
<button type="submit" class="btn btn-success">Add New Information</button>
</div>
</form>
<script src="https://cdn.ckeditor.com/ckeditor5/23.0.0/classic/ckeditor.js"></script>
<script>
ClassicEditor
.create( document.querySelector( '#content' ) )
.catch( error => {
console.error( error );
} );
</script>
I am trying to figure out why are the html tags not present on server side.
Thanks :)
*** UPDATE! ***
After doing php artisan config:cache, route:cache, and view:cache
The HTML tags are no longer being passed even on local.
you should add this script After the ckeditor.js script
<script>
CKEDITOR.replace('content');
</script>

How can I solve " Invalid datetime format: 1366 Incorrect integer value" Exception in Laravel 7?

I'm quite new to Laravel, I would like to update a column in mySQL database named "client_id" the name of the table is "projects" I would like to insert this column when a Client creates a new Project, because the project belongs to the Client who created it. "client_id" is the Primary Key (id) in the table called "clients". There is a relationship between "clients" table and "projects" table. I have written some code to solve this problem but I'm getting this Exception and the "client_id" column is not updated.
Please help.
Store Method in my Controller:
/**
* Store a newly created Project in storage.
*/
public function store(Request $request)
{
$request->validate([
'name' => 'required|string|max:255',
'description' => 'required|string|max:255',
'start_date' => 'required|date',
'start_time' => 'required|string|max:10',
]);
$project = Project::create([
'name' => $request->name,
'description' => $request->description,
'start_date' => $request->start_date,
'start_time' => $request->start_time,
]);
$loggedinId = Auth::id();
$project->update(['created_by' => $loggedinId]);
$userId = $loggedinId;
$clientId = Client::where('user_id', '=', $userId)->pluck('id')->all();
DB::table('projects')->where('created_by', '=', $loggedinId)->update([ 'client_id' => $clientId]);
return redirect()->back()->with('message', 'You have successfully submitted your Job Card');
}
Relationship in my Client Model:
/**
* #return HasMany
*/
public function projects()
{
return $this->hasMany(Project::class);
}
Relationship in my Project Model:
/**
* #return BelongsTo
*/
public function client()
{
return $this->belongsTo(Client::class, 'client_id');
}
Form In my Blade View:
<form method="POST" action="{{ route('client-jobcard.store') }}">
#csrf
<div class="form-group row">
<div class="col-sm-8">
<label for="name">{{ __('Job Card Name') }}</label><span class="required">*</span>
<input id="name" type="text" class="form-control{{ $errors->has('name') ? ' is-invalid' : '' }}" name="name" value="{{ old('name') }}" required autofocus>
#if ($errors->has('name'))
<span class="invalid-feedback">
<strong>{{ $errors->first('name') }}</strong>
</span>
#endif
</div>
</div>
<div class="form-group row">
<div class="col-sm-8">
<label for="description">{{ __('Job Card Description') }}</label><span class="required">*</span>
<textarea class="form-control{{ $errors->has('description') ? ' is-invalid' : '' }}" id="description" rows="4" style="height: 150px;" name="description" value="{{ old('description') }}" required autofocus></textarea>
#if ($errors->has('description'))
<span class="invalid-feedback">
<strong>{{ $errors->first('description') }}</strong>
</span>
#endif
</div>
</div>
<div class="form-group row">
<div class="col-sm-4">
<label for="start_date">Start Date</label><span class="required">*</span>
<input type="date" class="form-control" id="start_date" name="start_date" value="{{ old('start_date') }}" required>
</div>
<div class="col-sm-4">
<label for="submission_date">Start Time</label><span class="required">*</span>
<input type="text" class="form-control" id="start_time" name="start_time" value="{{ old('start_time') }}" required>
</div>
</div>
<div class="form-group row">
<div class="col-sm-4">
<button type="submit" class="btn btn-primary">
{{ __('Submit') }}
</button>
</div>
</div>
</form>
This line:
$clientId = Client::where('user_id', '=', $userId)->pluck('id')->all();
will return a column, not the single ID ("2") that you want.
Then, when you assign it to client_id which is an integer, the ORM will render it as the string [2] instead of the number 2, and that will give you an error.
Either retrieve just the first tuple from Client, or extract $clientId[0] manually (wasteful and not recommended).
You also have a second error I had overlooked:
'created_by', '=', $loggedinId
The above means that created_by must be an integer value, but the text of the error implies SQL expects it to be a datetime. You seem to have a wrong definition in the database.
your time field is in string , it has to be changed , it is not the same format
can you try this instead

How to upload image file in Laravel?

I have a form which contains several fields including the upload file button that I want to use as an image uploader, (<input type="file" name="image" id="image" class='image'>). Other fields works fine and uploads everything on the database, however, in the image field, the filename of the file I uploaded is giving me this file name:
C:\laragon\tmp\php859A.tmp
... What should I do? Thank you: ) Here are the codes:
this is the form:
<html>
<div class="col-md-offset-4 col-md-4">
<form action="{{ $action }}" method="POST" enctype="multipart/form-data">
<h1> {{ $header }} </h1>
<div class="form-group">
<label for="exampleInputEmail1">Name</label>
<input type="text" class="form-control" id="name" name="name" placeholder="Name" value="{{ $name }}">
</div>
<div class="form-group">
<label for="exampleInputPassword1">Description</label>
<input type="text" class="form-control" id="description" name="description" placeholder="Description" value="{{ $description }}">
</div>
<div class="form-group">
<label for="exampleInputPassword1">Price</label>
<input type="number" class="form-control" id="product_price" name="product_price" placeholder="Price" value="{{ $product_price }}">
</div>
<div class="form-group">
<label for="image">SELECT IMAGE TO UPLOAD</label><br>
<input type="file" name="image" id="image" class='image'>
</div>
<div class="col-md-offset-2">
{!! csrf_field() !!}
<button type="submit" class="btn btn-default col-md-5" style="background:#0099ff; color:#f2f2f2;">{{ $button }}</button>
<button type="submit" class="btn btn-default col-md-5" style="background:#f4f4f4; color:#000;">Cancel</button>
</div>
</form>
</div>
</html>
These are my functions Create and Store in the controller:
public function create()
{
$data['action'] = route('beverage_store');
$data['button'] = 'Add';
$data['header'] = 'ADD BEVERAGE';
$data['name'] = old('name');
$data['description'] = old('description');
$data['product_price'] = old('product_price');
$data['image'] = old('image');
return view('layouts.beverages.beverageform',$data);
}
/**
* Store a newly created resource in storage.
*
* #param \Illuminate\Http\Request $request
* #return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$input = $request->all();
#dd($input);
BeveragesModel::create($input);
return redirect()->route('beverages');
}
:)
Assuming you store the filename only on your database table, then you have to upload image somewhere else. So you could create something like:
private function upload($request)
{
$image_name = '';
if($request->hasFile('image'))
{
$image = $request->file('image');
$image_name = md5(uniqid()) . '.' . $image->getClientOriginalExtension();
$image->move(public_path() . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'beverages' . DIRECTORY_SEPARATOR, $image_name);
}
return $image_name;
}
public function store(Request $request)
{
$image_name = $this->upload($request);
$input = $request->all();
$beverage = BeveragesModel::create($input);
$beverage->image = $image_name;
$beverage->save();
return redirect()->route('beverages');
}

ngSubmit HTML attribute using angular template variable

I have two methods ngMake and ngUpdate. I have one form, PostForm. I want to reuse the same form, but add different functionality depending on the url.
I gain information about the url using
Controller
if ($location.path() === '/makepost') {
$scope.FormTitle = 'Make a Post';
$scope.FormAction = 'server/blog/makepost.php';
$scope.FormMethod = 'POST';
$scope.FormSubmit = "ngMake()"
};
if ($location.path().indexOf('update') !== -1) {
$scope.FormTitle = 'Update a Post';
$scope.FormAction = null;
$scope.FormMethod = 'POST';
$scope.FormSubmit = "ngUpdate()";
};
HTML Form
<div ng-controller="BlogController as blog">
<h3 class="text-center">{{FormTitle}}</h3>
<form ng-show='user != null' ng-submit="{{FormSubmit}}" role="form" class="form-group" name="PostForm">
<label>Title: </label>
<div ng-class="(PostForm.Title.$dirty && PostForm.Title.$invalid) ? 'has-warning' : 'has-success'" class="form-group has-feedback">
<input data-ng-model="post.Title" data-ng-minlength="3" data-ng-maxlength="255" name="Title" type="text" class="form-control" placeholder="Title" required/>
<span ng-class="(PostForm.Title.$dirty && PostForm.Title.$invalid) ? 'glyphicon-warning-sign' : 'glyphicon-ok'" class="glyphicon form-control-feedback"></span>
</div>
<label>Content: </label>
<div ng-class="(PostForm.Content.$dirty && PostForm.Content.$invalid) ? 'has-warning' : 'has-success'" class="form-group has-feedback">
<textarea data-ng-model="post.Content" rows="8" name="Content" type="text" class="form-control" placeholder="Content" required></textarea>
<span ng-class="(PostForm.Content.$dirty && PostForm.Content.$invalid) ? 'glyphicon-warning-sign' : 'glyphicon-ok'" class="glyphicon form-control-feedback"></span>
</div>
<div ng-controller="AuthController as auth">
<input class="ng-hide" type="number" data-ng-model="post.UserID" name="UserID" value="{{user.ID}}">
</div>
<br>
<input type="submit" ng-class="(PostForm.$valid) ? 'btn-success' : 'disabled'" class="btn btn-block btn-default">
</form>
<p ng-show='user == null' class="text-center">You must be logged in in order to {{FormTitle | lowercase}}</p>
Explination
The {{FormSubmit}} template variable probably executes afterwards and causes a problem which doesn't permit the form to execute. I am open to suggestions, I want to reuse the same form. I read that ngSubmit requires a type="submit" button or input element contained within the form tags, I have that. I do not have any ng-clicks which might hinder the form.
I am open to suggestions
If there are any other problems with the form or the entire project please let me know, even if it is just a "bette practice".
The full project
https://github.com/AquaSolid/RAMA_Angular_PHP
Basically, I wised up. I contained the logic in the back-end. I created a function to choose which function to use. Meanwhile the the form contains the attribute ng-submit="chooseSubmit()". That's about it..
$scope.chooseSubmit = function() {
if ($scope.FormSubmit) {
if ($scope.FormSubmit === 'ngMake()') {
$scope.ngMake();
} else {
$scope.ngUpdate();
};
}
};

Blade Templating Input Type Value

In Html forms i can do this as like :
<input type="hidden" name="token" value="{{ $token }}">
I would like to do this in full blade templating like this :
{{ Form::hidden('token', $token, array('class' => 'form-control')) }}
But the second option doesn't pass the $token value. Where do i go wrong ?
-- UPDATE --
I have found the solution for this :
It is quite easy question, but had to be careful while naming the inputs in blade templating.
This is my first form, which is working nice :
<form action="{{ action('RemindersController#postReset') }}" method="POST">
<input type="hidden" name="token" value="{{ $token }}">
Email<input type="email" name="email">
Password<input type="password" name="password">
Password<input type="password" name="password_confirmation">
<input type="submit" value="Reset Password">
</form>
**In blade templating form it was like **
{{ Form::open(array('action' => 'RemindersController#postReset')) }}
{{ Form::hidden('token', $token , array('class' => 'form-control')) }}
{{ Form::email('email', null, array('class'=>'form-control input-sm','placeholder'=>'Mail address')) }}
{{ Form::password('pass', array('class'=>'form-control input-sm','placeholder'=>'New Password')) }}
{{ Form::password('pass_conf', array('class'=>'form-control input-sm','placeholder'=>'Confirm Password')) }}
{{ Form::submit('Submit', array('class'=>'btn btn-info btn-block')) }}
{{ Form::close() }}
--SOLUTION--
So the error is :
In 1st form,
Password<input type="password" name="password">
Password<input type="password" name="password_confirmation">
In 2nd form,
{{ Form::password('pass', array('class'=>'form-control
input-sm','placeholder'=>'New Password')) }}
{{Form::password('pass_conf', array('class'=>'form-control
input-sm','placeholder'=>'Confirm Password')) }}
input names are password and password_confirmation, and in the second form they are named pass and pass_conf.
I changed pass to password and pass_conf to password_confirmation and it's now working fine.
Thank you for your feedbacks and patience.
It's just a guess but you can try to put also static value:
{{ Form::hidden('token', 'some token here', array('class' => 'form-control')) }}
and now check if it is in page source.
If it's not it means that you probably redirect to form using withInput and then Larravel fills the form with the same data as previous even if you set value manually to any HTML form element.
In this case you could make redirection using:
->withInput(Input::except('token'));
If it's the case you can read more about it in this topic: Laravel redirection using withInput doesn't allow to change inputs values
EDIT
You should try to change:
return Redirect::back()->with('error', Lang::get($response));
into:
return Redirect::back()->with(array ('error', 'token'), array(Lang::get($response), Input::get('token'));