Laravel display image uploaded in view from database - php

I want to display images uploaded in view file to the database using laravel...the image are not loaded...
below is my view file where i want to display my image
#extends('layouts.app')
#section('content')
<div class="container">
<div class="row justify-content-center">
<div class="col-md-8">
#foreach($infor as $inform)
<div class="card mb-3">
<img src="{{ asset('storage/uploads/'.$inform->imogi) }}" style="max-width:20%;" alt="Wild Landscape"/>
<div class="card-body">
<div style="text-align: right;">
<small style="color:#3490dc;">{{$inform->organazation}}</small> <small><i class="fa fa-calendar" style="color:#3490dc" aria-hidden="true"></i> {{ $inform->created_at->format('d/m/Y') }}</small>
</div>
<h5 class="card-title"><i class="fa fa-user-circle-o" style="color:#3490dc" aria-hidden="true"></i> {{$inform->name}}</h5>
<!--LIVEWIRE online status-->
<div wire:key="UNIQUE_ID">
#if($inform->isOnline())
<small style="color:#3490dc;"> operative </small>
#else
<small style="color:#3490dc;"> detached</small>
#endif
</div>
<small><i class="fa fa-map-marker" style="color:#3490dc" aria-hidden="true"></i> {{$inform->location}}</small>
<hr/>
<h6 class="card-title"><b>{{$inform->title}}</b></h6>
<p class="card-text">
{{$inform->message}}
</p>
<small><small style="color:#3490dc;"><u><b>Qualifications:</b></u></small> {{$inform->qualifications}}</small>
<div style="text-align: right;">
<small><i class="fa fa-phone" style="color:#3490dc" aria-hidden="true"></i> {{$inform->contact}}</small>
</div>
</div>
</div>
<br/>
#endforeach
</div>
</div>
</div>
#include('footer')
#endsection
below is my upload controller
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class FileUploadController extends Controller
{
public function fileUpload()
{
return view('fileUpload');
}
//
public function fileUploadPost(Request $request)
{
$request->validate([
'file' => 'required|mimes:pdf,xlx,csv|max:2048',
]);
$fileName = time().'.'.$request->file->extension();
$request->file->move(public_path('uploads'), $fileName);
return back()
->with('success','You have successfully upload file.')
->with('file',$fileName);
}
}
Here is my storage path in filesystems.php
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
],
And below is the blade view where the image is being uploaded
#extends('layouts.app')
#section('content')
<div class="container">
<div class="row justify-content-center">
<div class="col-md-8">
<form action="message" method="POST">
#csrf
<div class="form-group">
<label for="exampleFormControlInput1"><i style="color:#3490dc" class="fa fa-user" style="font-size:24px"></i> Name</label>
<input type="text" class="form-control" id="exampleFormControlInput1" name="name" value="{{ auth()->user()->name }}" readonly>
</div>
<div class="form-group">
<label for="exampleFormControlInput1"><i style="color:#3490dc" class="fa fa-building-o" style="font-size:24px"></i> Organazation</label>
<input type="text" class="form-control" id="exampleFormControlInput1" name="organazation">
<span style="color: red;"><small>#error('organazation'){{$message}}#enderror</small></span>
<small>Type your organazation or state whether individual</small>
</div>
<div class="form-group">
<label for="exampleFormControlInput1"><i style="color:#3490dc" class="fa fa-map-marker" style="font-size:24px"></i> Location</label>
<input type="text" class="form-control" id="exampleFormControlInput1" name="location">
<span style="color: red;"><small>#error('location'){{$message}}#enderror</small></span>
<small>Type your location</small>
</div>
<div class="form-group">
<label for="exampleFormControlInput1"><i style="color:#3490dc" class="fa fa-pencil" style="font-size:24px"></i> Job title</label>
<input type="text" class="form-control" id="exampleFormControlInput1" name="title">
<span style="color: red;"><small>#error('title'){{$message}}#enderror</small></span>
<small>Enter the title for the job</small>
</div>
<div class="form-group">
<label for="exampleFormControlTextarea1"><i style="color:#3490dc" class="fa fa-pencil" style="font-size:24px"></i> Job description</label>
<textarea type="text" class="form-control" id="exampleFormControlTextarea1" rows="3" name="message"></textarea>
<span style="color: red;"><small>#error('message'){{$message}}#enderror</small></span>
<small>Describe the type of job being offered</small>
</div>
<div class="form-group">
<label for="exampleFormControlInput1"><i style="color:#3490dc" class="fa fa-file" style="font-size:24px"></i> Qualifications</label>
<input type="text" class="form-control" id="exampleFormControlInput1" name="qualifications">
<span style="color: red;"><small>#error('qualifications'){{$message}}#enderror</small></span>
<small>Enter the qualifications and experience required</small>
</div>
<div class="form-group">
<label for="exampleFormControlInput1"><i style="color:#3490dc" class="fa fa-phone" style="font-size:24px"></i> Contacts</label>
<input type="text" class="form-control" id="exampleFormControlInput1" name="contact">
<span style="color: red;"><small>#error('contact'){{$message}}#enderror</small></span>
<small>Enter phone contacts</small>
</div>
<form action="{{ route('file.upload.post') }}" method="POST" enctype="multipart/form-data">
#csrf
<div class="row">
<div class="col-md-6">
<input type="file" class="form-control" name="imogi">
</div>
</div>
<span style="color: red;"><small>#error('imogi'){{$message}}#enderror</small></span>
<small>Select business logo if any or implicating image</small>
<br/>
<br/>
<button type="submit" class="btn btn-primary">Post</button>
</form>
<br/>
</form>
</div>
</div>
</div>
#include('footer')
#endsection
I can display any image in my view except the one i uploaded...i dont know where am getting this wrong...i will appreciate any kind of help
Thank You!

you should try:
{{ URL::asset('storage/uploads/'.$inform->imogi) }}

Related

Laravel 8 - Old inputs and validation error messages are not working

I am trying to display the error div below a certain field if the validation for that input failed along with the previous input on the designated field.
Here's my progress so far:
in my controller file inside the store function (UserController > store):
public function store(Request $request)
{
$validationRules = array(
'first_name' => 'required|min:2|max:150',
'last_name' => 'required|min:2|max:150',
'gender' => 'required',
'birthdate' => 'required',
'user_contact' => 'required|min:10|max:20',
'email' => 'required|unique:users|max:150'
);
$validator = Validator::make($request->all(), $validationRules);
if($validator->fails()){
//dd($validator)
return redirect(route('user.create'))->withInput()->withErrors($validator);
}
.....
When I try to print $validator using dd() it does not have any problem and it contains the validation error messages, all inputs and validation rules.
Here's my snippet code in the create.blade.php (view):
<form class="form-horizontal" method = "POST" action = "{{ route('user.store') }}">
#csrf
<div class="form-group row">
<div class="col-md-12">
<strong><font color="red">*</font> Indicates required fields.</strong>
</div>
<div class="col-md-4">
<label for="u_fname" class="col-sm-6 col-form-label">First Name <font color="red">*</font></label>
<div class="input-group mb-2 {{$errors->has('u_fname') ? 'has-error' : ''}}" >
<div class="input-group-prepend">
<span class="input-group-text"><i class="fa fa-user" aria-hidden="true"></i></span>
</div>
<input type="text"
class="form-control"
id="first_name"
name = "first_name"
value="{{ old('first_name') }}"
minlength="2"
maxlength="150"
required/>
#error('first_name')
<div class="alert-danger">{{$errors->first('first_name') }} </div>
#enderror
</div>
</div>
<div class="col-md-4">
<label for="u_lname" class="col-sm-6 col-form-label">Last Name <font color="red">*</font></label>
<div class="input-group mb-2 {{$errors->has('u_lname') ? 'has-error' : ''}}" >
<div class="input-group-prepend">
<span class="input-group-text"><i class="fa fa-user" aria-hidden="true"></i></span>
</div>
<input type="text"
class="form-control"
id="last_name"
name = "last_name"
value="{{ old('last_name') }}"
minlength="2"
maxlength="150"
required/>
#error('last_name')
<div class="alert-danger">{{$errors->first('last_name') }} </div>
#enderror
</div>
</div>
<div class="col-md-4">
<label for="u_gender" class="col-sm-6 col-form-label">Gender <font color="red">*</font></label>
<div class="input-group mb-2 {{$errors->has('u_gender') ? 'has-error' : ''}}" >
<div class="input-group-prepend">
<span class="input-group-text"><i class="fas fa-venus-mars"></i></span>
</div>
<select class = "form-control" id = "gender" name = "gender" required>
<option value = "M">Male</option>
<option value = "F">Female</option>
</select>
#error('gender')
<div class="alert-danger">{{$errors->first('gender') }} </div>
#enderror
</div>
</div>
<div class="col-md-4">
<label for="u_birthdate" class="col-sm-6 col-form-label">Birth Date <font color="red">*</font></label>
<div class="input-group mb-2 {{$errors->has('u_birthdate') ? 'has-error' : ''}}" >
<div class="input-group-prepend">
<span class="input-group-text"><i class="far fa-calendar-alt"></i></span>
</div>
<input type="text"
class="form-control"
id="birthdate"
name = "birthdate"
value="{{ old('birthdate') }}"
required/>
<div class="alert-danger">{{$errors->first('birthdate') }} </div>
</div>
</div>
<div class="col-md-4">
<label for="u_contact" class="col-sm-6 col-form-label">Contact Number <font color="red">*</font></label>
<div class="input-group mb-2 {{$errors->has('u_contact') ? 'has-error' : ''}}" >
<div class="input-group-prepend">
<span class="input-group-text"><i class="fas fa-phone"></i></span>
</div>
<input type="text"
class="form-control"
id="user_contact"
name = "user_contact"
value="{{ old('user_contact') }}"
onkeyup="this.value=this.value.replace(/[^\d]/,'')"
minlength="10"
maxlength="20"
required/>
#error('user_contact')
<div class="alert-danger">{{$errors->first('user_contact') }} </div>
#enderror
</div>
</div>
<div class="col-md-4">
<label for="u_email" class="col-sm-6 col-form-label">E-Mail Address<font color="red">*</font></label>
<div class="input-group mb-2 {{$errors->has('u_email') ? 'has-error' : ''}}" >
<div class="input-group-prepend">
<span class="input-group-text"><i class="fas fa-at"></i></span>
</div>
<input type="email"
class="form-control"
id="email"
name = "email"
value="{{ old('email') }}"
minlength="10"
maxlength="150"
required/>
#error('email')
<div class="alert-danger">{{$errors->first('email') }} </div>
#enderror
</div>
</div>
<div class="col-md-4">
<label for="u_utype" class="col-sm-6 col-form-label">User Type <font color="red">*</font></label>
<div class="input-group mb-2 {{$errors->has('u_utype') ? 'has-error' : ''}}" >
<div class="input-group-prepend">
<span class="input-group-text"><i class="fas fa-user-cog"></i></span>
</div>
<select class = "form-control" id = "u_type_input" name = "u_type_input" required>
<option value = "E">Employee</option>
<option value = "A">Administrator</option>
</select>
#error('u_type_input')
<div class="alert-danger">{{$errors->first('u_type_input') }} </div>
#enderror
</div>
</div>
</div>
</div>
<div class="card-footer">
<button type="submit" class="btn btn-default float-right" name = "submit_create" id = "submit_create">Submit</button>
</div>
</form>
Notice that I removed the autocomplete=off because I read some posts that this causes the problem but still doesn't work in my case.
I've been reading all stackoverflow posts related on my problem but most of the scenario problem occured on Laravel 5 and I use the current latest version of Laravel Framework which is Laravel 8.
What seems to be the cause of the problem? and how should I retain the
old/previous inputs and show the error messages after the failed
validation? I suspect that the cause of the problem lies on the blade
file or related to the resources like bootstrap.
you can try this to redirect
if ($validator->fails())
{
return redirect()->back()->withErrors($validator->errors());
}
and while showing into the blade file try this one
#error('user_contact')
<div style="color: red;">{{ $message }}</div>
#enderror

GET not supported although I am using PUT in Laravel

I am using Laravel 7 and I can add entries and view them from the database. When I try to edit or update edited changes, I either get a warning from Laravel saying that the The GET method is not supported for this route. Supported methods: PUT. However, I am using PUT in both the web.php route as well as in my method calls. Surely I am doing something wrong.
Here is a view of my Routes calling artisan route:list
in my Route Group in web.php Here are the controllers I am calling:
Route::group(['middleware' => ['auth', 'isAdmin']], function () {
Route::get('/dashboard', function () {
return view('admin.dashboard');
});
Route::get('registered-user', 'Admin\RegisteredController#index');
Route::get('registered-empresa', 'Admin\EmpresaController#index');
Route::get('role-edit/{id}', 'Admin\RegisteredController#edit');
Route::put('role-update/{id}', 'Admin\RegisteredController#updaterole');
Route::post('save-empresa', 'Admin\EmpresaController#store');
Route::put('edit-empresa/{id}', 'Admin\EmpresaController#update');
});
Here is the update function I created in EmpresaController.php:
public function update(Request $request, $id)
{
$this->validate($request, [
'erfc' => 'required',
'enombre' => 'required',
'ecalle' => 'required',
'ecolonia' => 'required',
'eciudad' => 'required',
'eestado' => 'required',
'ecpostal' => 'required',
'epais' => 'required',
]);
$empr = Empresa::find($id);
$empr->erfc = $request->input('erfc');
$empr->enombre = $request->input('enombre');
$empr->ecalle = $request->input('ecalle');
$empr->ecolonia = $request->input('ecolonia');
$empr->eciudad = $request->input('eciudad');
$empr->eestado = $request->input('eestado');
$empr->ecpostal = $request->input('ecpostal');
$empr->epais = $request->input('epais');
$empr->update();
return redirect('/registered-empresa')->with('status', 'Empresa se actualizó correctamente.');
}
And finally, here is the location of my empresas table where I both add, view and update my table in my index.blade.php file:
#extends('layouts.admin')
#section('content')
<div class="container-fluid mt-5">
<!-- Heading -->
<div class="card mb-4 wow fadeIn">
<!--Card content-->
<div class="card-body d-sm-flex justify-content-between">
<h4 class="mb-2 mb-sm-0 pt-1">
Home Page
<span>/</span>
<span>Empresas Registradas</span>
</h4>
#if (session('status'))
<div class="alert alert-success" role="alert">
{{ session('status') }}
</div>
#endif
<div class="modal fade" id="modalRegisterForm" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header text-center">
<h4 class="modal-title w-100 font-weight-bold">Añadir Empresa</h4>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<form action="/save-empresa" method="POST">
{{ csrf_field() }}
<div class="modal-body mx-3">
<div class="md-form mb-1">
<input type="text" name="erfc" id="orangeForm-erfc" class="form-control validate">
<label data-error="wrong" data-success="right" for="orangeForm-erfc">RFC</label>
</div>
<div class="md-form mb-1">
<input type="text" name="enombre" id="orangeForm-enombre" class="form-control validate">
<label data-error="wrong" data-success="right" for="orangeForm-enombre">Nombre</label>
</div>
<div class="md-form mb-1">
<input type="text" name="ecalle" id="orangeForm-ecalle" class="form-control validate">
<label data-error="wrong" data-success="right" for="orangeForm-ecalle">Calle</label>
</div>
<div class="md-form mb-1">
<input type="text" name="ecolonia" id="orangeForm-ecolonia" class="form-control validate">
<label data-error="wrong" data-success="right" for="orangeForm-ecolonia">Colonia</label>
</div>
<div class="md-form mb-1">
<input type="text" name="eciudad" id="orangeForm-eciudad" class="form-control validate">
<label data-error="wrong" data-success="right" for="orangeForm-eciudad">Ciudad</label>
</div>
<div class="md-form mb-1">
<input type="text" name="eestado" id="orangeForm-eestado" class="form-control validate">
<label data-error="wrong" data-success="right" for="orangeForm-eestado">Estado</label>
</div>
<div class="md-form mb-1">
<input type="text" name="ecpostal" id="orangeForm-ecpostal" class="form-control validate">
<label data-error="wrong" data-success="right" for="orangeForm-ecpostal">Codigo Postal</label>
</div>
<div class="md-form mb-1">
<input type="text" name="epais" id="orangeForm-epais" class="form-control validate">
<label data-error="wrong" data-success="right" for="orangeForm-epais">País</label>
</div>
<div style="display: none;" class="md-form mb-1">
<input type="text" name="euser" readonly id="orangeForm-euser" class="form-control validate" value="{{ Auth::user()->id }}">
</div>
<div style="display: none;" class="md-form mb-1">
<input type="text" name="eregby" readonly id="orangeForm-eregby" class="form-control validate" value="{{ Auth::user()->id }}">
</div>
</div>
<div class="modal-footer d-flex justify-content-center">
<button type="submit" class="btn btn-deep-orange">Añadir</button>
</div>
</form>
</div>
</div>
</div>
<div class="text-center">
<i class="fa fa-plus" aria-hidden="true"></i> Add
</div>
<!--edit modal start-->
<div class="modal fade" id="editModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header text-center">
<h4 class="modal-title w-100 font-weight-bold">Editar Empresa</h4>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<form action="edit-empresa/" id="editForm">
{{ csrf_field() }}
#method('PUT')
<div class="modal-body mx-3">
<div class="md-form mb-1">
<input placeholder="RFC" type="text" name="erfc" id="erfc" class="form-control validate">
</div>
<div class="md-form mb-1">
<input placeholder="Nombre" type="text" name="enombre" id="enombre" class="form-control validate">
</div>
<div class="md-form mb-1">
<input placeholder="Calle" type="text" name="ecalle" id="ecalle" class="form-control validate">
</div>
<div class="md-form mb-1">
<input placeholder="Colonia" type="text" name="ecolonia" id="ecolonia" class="form-control validate">
</div>
<div class="md-form mb-1">
<input placeholder="Ciudad" type="text" name="eciudad" id="eciudad" class="form-control validate">
</div>
<div class="md-form mb-1">
<input placeholder="Estado" type="text" name="eestado" id="eestado" class="form-control validate">
</div>
<div class="md-form mb-1">
<input placeholder="Codigo Postal" type="text" name="ecpostal" id="ecpostal" class="form-control validate">
</div>
<div class="md-form mb-1">
<input placeholder="País" type="text" name="epais" id="epais" class="form-control validate">
</div>
<div style="display: none;" class="md-form mb-1">
<input type="text" name="euser" readonly id="euser" class="form-control validate" value="{{ Auth::user()->id }}">
</div>
<div style="display: none;" class="md-form mb-1">
<input type="text" name="eregby" readonly id="eregby" class="form-control validate" value="{{ Auth::user()->id }}">
</div>
</div>
{{-- <div class="modal-footer d-flex justify-content-center">
<button type="submit" class="btn btn-deep-orange">Editar</button>
</div> --}}
<div class="modal-footer d-flex justify-content-center">
<button type="submit" class="btn btn-deep-orange">Editar</button>
</div>
</form>
</div>
</div>
</div>
<!--end edit modal-->
</div>
</div>
<!-- Heading -->
<!--Grid row-->
<!--Grid column-->
<div class="row">
<!--Card-->
<div class="col-md-12 mb-4">
<!--Card content-->
<div class="card">
<!-- List group links -->
<div class="card-body">
<table id="datatable2" class="table table-bordered">
<thead>
<tr>
<th>RFC</th>
<th>Nombre</th>
<th>Calle</th>
<th>Colonia</th>
<th>Ciudad</th>
<th>Estado</th>
<th>Codigo Postal</th>
<th>País</th>
<th>Acción</th>
</tr>
</thead>
<tbody>
#foreach ($empresas as $empresa)
<tr>
<td>{{ $empresa->erfc }}</td>
<td>{{ $empresa->enombre }}</td>
<td>{{ $empresa->ecalle }}</td>
<td>{{ $empresa->ecolonia }}</td>
<td>{{ $empresa->eciudad }}</td>
<td>{{ $empresa->eestado }}</td>
<td>{{ $empresa->ecpostal }}</td>
<td>{{ $empresa->epais }}</td>
<td>
<div class="text-center">
Editar
<a class="badge badge-pill btn-danger px-3 py-2" href="">Borrar</a>
</div>
</td>
</tr>
#endforeach
</tbody>
</table>
</div>
<!-- List group links -->
</div>
</div>
<!--/.Card-->
</div>
<!--Grid row-->
</div>
#endsection
#section('scripts')
<script>
$(document).ready(function() {
let table = $('#datatable2').DataTable();
// Start edit record
table.on('click', '.edit', function() {
$tr = $(this).closest('tr');
if($($tr).hasClass('child')) {
$tr = $tr.prev('.parent');
}
let data = table.row($tr).data();
console.log(data);
$('#erfc').val(data[0]);
$('#enombre').val(data[1]);
$('#ecalle').val(data[2]);
$('#ecolonia').val(data[3]);
$('#eciudad').val(data[4]);
$('#eestado').val(data[5]);
$('#ecpostal').val(data[6]);
$('#epais').val(data[7]);
$('#editForm').attr('action', '/edit-empresa/'+data[0]);
$('#editModal').modal('show');
});
// End edit record
});
</script>
#endsection
I am pretty sure it is in this file that I am doing something wrong. Any help on how I can do this better or if I missed something, I would surely appreciate it. Thank you in advance.
in web.php
Route::patch('edit-empresa/{id}', 'Admin\EmpresaController#update');
index.blade.php
#method('PATCH')
You need to specify method as POST when defining the form even though you are including the #method('PUT') inside the form. That is because HTML does not support PUT method directly, and by default it will be a GET. So to correct:
Change this:
<form action="edit-empresa/" id="editForm">
TO
<form action="edit-empresa/" id="editForm" method="POST">
For some reason I could not get this to work using the modal and jquery method so I eliminated the datatables jquery from the bottom of the index.blade.php. My first error was to not call the data first. I created a seperate file called edit.blade.php within the view-admin-empresa folder. Here is the code:
#extends('layouts.admin')
#section('content')
<div class="container-fluid mt-5">
<!-- Heading -->
<div class="card mb-4 wow fadeIn">
<!--Card content-->
<div class="card-body d-sm-flex justify-content-between">
<h4 class="mb-2 mb-sm-0 pt-1">
<span>Empresa Registrada - Editar Empresa</span>
</h4>
</div>
</div>
<!-- Heading -->
<div class="row">
<div class="col-md-12">
<div class="card">
<div class="card-header">
<h4 class="card-title">Editar Empresa</h4>
<form action="{{ url('empresa-update/'.$empresa->id) }}" id="editForm" method="POST">
{{ csrf_field() }}
{{ method_field('PUT') }}
<div class="modal-body mx-3">
<div class="md-form mb-1">
<label for="erfc">RFC</label>
<input value="{{ $empresa->erfc }}" type="text" name="erfc" id="erfc" class="form-control validate">
</div>
<div class="md-form mb-1">
<label for="enombre">Nombre</label>
<input value="{{ $empresa->enombre }}" type="text" name="enombre" id="enombre" class="form-control validate">
</div>
<div class="md-form mb-1">
<label for="ecalle">Calle</label>
<input value="{{ $empresa->ecalle }}" type="text" name="ecalle" id="ecalle" class="form-control validate">
</div>
<div class="md-form mb-1">
<label for="ecolonia">Colonia</label>
<input value="{{ $empresa->ecolonia }}" type="text" name="ecolonia" id="ecolonia" class="form-control validate">
</div>
<div class="md-form mb-1">
<label for="ecuidad">Ciudad</label>
<input value="{{ $empresa->eciudad }}" type="text" name="eciudad" id="eciudad" class="form-control validate">
</div>
<div class="md-form mb-1">
<label for="eestado">Estado</label>
<input value="{{ $empresa->eestado }}" type="text" name="eestado" id="eestado" class="form-control validate">
</div>
<div class="md-form mb-1">
<label for="ecpostal">Codigo Postal</label>
<input value="{{ $empresa->ecpostal }}" type="text" name="ecpostal" id="ecpostal" class="form-control validate">
</div>
<div class="md-form mb-1">
<label for="epais">País</label>
<input value="{{ $empresa->epais }}" type="text" name="epais" id="epais" class="form-control validate">
</div>
<div style="display: none;" class="md-form mb-1">
<input type="text" name="euser" readonly id="euser" class="form-control validate" value="{{ Auth::user()->id }}">
</div>
<div style="display: none;" class="md-form mb-1">
<input type="text" name="eregby" readonly id="eregby" class="form-control validate" value="{{ Auth::user()->id }}">
</div>
</div>
<div class="modal-footer d-flex justify-content-center">
Cancelar
<button type="submit" class="btn btn-deep-orange">Editar</button>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
#endsection
Then in the web.php, I created the following routes:
Route::group(['middleware' => ['auth', 'isAdmin']], function () {
Route::get('/dashboard', function () {
return view('admin.dashboard');
});
Route::get('registered-user', 'Admin\RegisteredController#index');
Route::get('registered-empresa', 'Admin\EmpresaController#index');
Route::get('role-edit/{id}', 'Admin\RegisteredController#edit');
Route::put('role-update/{id}', 'Admin\RegisteredController#updaterole');
Route::post('save-empresa', 'Admin\EmpresaController#store');
Route::get('/edit-empresa/{id}', 'Admin\EmpresaController#edit');
Route::put('/empresa-update/{id}', 'Admin\EmpresaController#update');
});
As mentioned earlier, I eliminated the edit modal and redirected to the empresa edit.blade.php file.
Now, I am able to edit without any problems. Thank you to Arjun bhati and user3532758 for taking a stab at this issue. I really appreciate it.

redirect back to register page then add flash message upon registering using the make:auth() in Laravel

Hi i have this laravel app. Im using the make:auth() for my login and registration system. By default the registration will automatically goes to /home page. Now, i want to redirect my register page to itself then add a flash message to it. Not automatically login. I also added the Session flash message code to it. How will i able to achieve this? this is my code below. Can someone help me figured this thing out?
Any help is muchly appreciated.TIA
app\http\controllers\auth\RegisterController.php :
use RegistersUsers;
/**
* Where to redirect users after registration.
*
* #var string
*/
protected $redirectTo = '/home';
/**
* Create a new controller instance.
*
* #return void
*/
public function __construct()
{
$this->middleware('guest');
}
/**
* Get a validator for an incoming registration request.
*
* #param array $data
* #return \Illuminate\Contracts\Validation\Validator
*/
protected function validator(array $data)
{
return Validator::make($data, [
'firstName' => 'required|string|max:255',
'middleName'=> 'required|string|max:255',
'lastName'=> 'required|string|max:255',
'address'=> 'required|string|max:255',
'contactNumber'=> 'required|string|max:255',
'username'=> 'required|string|max:255',
'email' => 'required|string|email|max:255|unique:users',
'password' => 'required|string|min:6|confirmed',
]);
}
/**
* Create a new user instance after a valid registration.
*
* #param array $data
* #return \App\User
*/
protected function create(array $data)
{
$membersNumber = time() . rand(10*45, 100*98);
Session::flash('success', 'You are successfully registered! Serapio.ph will review your submitted documents and will text you if you can login.');
return User::create([
'members_number'=>$membersNumber,
'first_name' => $data['firstName'],
'middle_name'=>$data['middleName'],
'last_name'=>$data['lastName'],
'address'=>$data['address'],
'contact_number'=>$data['contactNumber'],
'username'=>$data['username'],
'reference_person'=>$data['referencePerson'],
'email' => $data['email'],
'password' => bcrypt($data['password']),
]);
}
register.blade.php :
#extends('layouts.app')
#section('title', 'Register | Serapio.ph')
#section('content')
<!-- BREADCRUMBS -->
<div class="page-header">
<div class="container">
<h1 class="page-title pull-left">Register</h1>
<ol class="breadcrumb">
<li>Home</li>
<li class="active">Register</li>
</ol>
</div>
</div>
<!-- END BREADCRUMBS -->
<div class="container">
<div class="row">
<form class="form-horizontal" method="POST" action="{{ route('register') }}">
<div class="col-md-6 form-horizontal">
<!-- REGISTRATION FORM -->
<br>
<h2 class="section-heading">Member's Sign Up Info</h2>
{{ csrf_field() }}
#if (session('success'))
<p class="alert alert-success">{{ Session::get('success') }}</p>
#endif
<div class="form-group">
<div class="col-sm-12">
<div class="input-group">
<input type="text" class="form-control" id="firstName" name="firstName" value="{{ old('firstName') }}" placeholder="First Name" />
<span class="input-group-addon"><i class="fa fa-user"></i></span>
</div>
</div>
</div>
<div class="form-group">
<div class="col-sm-12">
<div class="input-group">
<input type="text" class="form-control" id="middleName" name="middleName" value="{{ old('middleName') }}" placeholder="Middle Name" />
<span class="input-group-addon"><i class="fa fa-user"></i></span>
</div>
</div>
</div>
<div class="form-group">
<div class="col-sm-12">
<div class="input-group">
<input type="text" class="form-control" id="lastName" name="lastName" value="{{ old('lastName') }}" placeholder="Last Name" />
<span class="input-group-addon"><i class="fa fa-user"></i></span>
</div>
</div>
</div>
<div class="form-group">
<div class="col-sm-12">
<div class="input-group">
<input type="text" class="form-control" id="address" name="address" value="{{ old('address') }}" placeholder="Address" />
<span class="input-group-addon"><i class="fa fa-map-pin"></i></span>
</div>
</div>
</div>
<div class="form-group">
<div class="col-sm-12">
<div class="input-group">
<input type="text" class="form-control" id="contactNumber" name="contactNumber" value="{{ old('contactNumber') }}" placeholder="Contact Number" />
<span class="input-group-addon"><i class="fa fa-phone-square"></i></span>
</div>
</div>
</div>
</div>
<div class="col-md-6 form-horizontal" style='margin-top:95px;'>
<div class="form-group">
<div class="col-sm-12">
<div class="input-group">
<input type="text" class="form-control" id="referencePerson" name="referencePerson" value="" placeholder="Reference Person (Optional)" />
<span class="input-group-addon"><i class="fa fa-user"></i></span>
</div>
</div>
</div>
<div class="form-group">
<div class="col-sm-12">
<div class="input-group">
<input type="text" class="form-control" id="username" name="username" value="{{ old('username') }}" placeholder="Username" />
<span class="input-group-addon"><i class="fa fa-user"></i></span>
</div>
</div>
</div>
<div class="form-group{{ $errors->has('email') ? ' has-error' : '' }}">
<label for="email" class="control-label sr-only">Email</label>
<div class="col-sm-12">
<div class="input-group">
<input type="email" class="form-control" id="email" name="email" value="{{ old('email') }}" placeholder="Email">
<span class="input-group-addon"><i class="fa fa-envelope"></i></span>
#if ($errors->has('email'))
<span class="help-block">
<strong>{{ $errors->first('email') }}</strong>
</span>
#endif
</div>
</div>
</div>
<div class="form-group{{ $errors->has('password') ? ' has-error' : '' }}">
<label for="password" class="control-label sr-only">Password</label>
<div class="col-sm-12">
<div class="input-group">
<input type="password" class="form-control" id="password" name="password" value="" placeholder="Password">
<span class="input-group-addon"><i class="fa fa-lock"></i></span>
#if ($errors->has('password'))
<span class="help-block">
<strong>{{ $errors->first('password') }}</strong>
</span>
#endif
</div>
</div>
</div>
<div class="form-group">
<label for="password2" class="control-label sr-only">Repeat Password</label>
<div class="col-sm-12">
<div class="input-group">
<input id="password-confirm" type="password" class="form-control" name="password_confirmation" required placeholder="Repeat Password">
<span class="input-group-addon"><i class="fa fa-lock"></i></span>
</div>
</div>
</div>
<div class="form-group">
<div class="col-sm-12">
<label style="color:red;">Note* Upload Seaman's Book/Students ID<br><i>Please upload file using PDF or JPG</i></label>
<input type="file" name="pdf" />
</div>
</div>
<div class="form-group">
<div class="col-sm-12">
<input type="checkbox" name="checkbox" /> Terms and Condition
</div>
</div>
<div class="form-group">
<div class="col-sm-12">
<button type="submit" class="pull-right btn btn-success btn-lg"><i class="fa fa-check-circle"></i> Create Account</button>
</div>
</div>
</div>
</form>
<!--<div class="col-md-8 col-md-offset-2">
<div class="panel panel-default">
<div class="panel-heading">Register</div>
<div class="panel-body">
<form class="form-horizontal" method="POST" action="{{ route('register') }}">
{{ csrf_field() }}
<div class="form-group{{ $errors->has('name') ? ' has-error' : '' }}">
<label for="name" class="col-md-4 control-label">Name</label>
<div class="col-md-6">
<input id="name" type="text" class="form-control" name="name" value="{{ old('name') }}" required autofocus>
#if ($errors->has('name'))
<span class="help-block">
<strong>{{ $errors->first('name') }}</strong>
</span>
#endif
</div>
</div>
<div class="form-group{{ $errors->has('email') ? ' has-error' : '' }}">
<label for="email" class="col-md-4 control-label">E-Mail Address</label>
<div class="col-md-6">
<input id="email" type="email" class="form-control" name="email" value="{{ old('email') }}" required>
#if ($errors->has('email'))
<span class="help-block">
<strong>{{ $errors->first('email') }}</strong>
</span>
#endif
</div>
</div>
<div class="form-group{{ $errors->has('password') ? ' has-error' : '' }}">
<label for="password" class="col-md-4 control-label">Password</label>
<div class="col-md-6">
<input id="password" type="password" class="form-control" name="password" required>
#if ($errors->has('password'))
<span class="help-block">
<strong>{{ $errors->first('password') }}</strong>
</span>
#endif
</div>
</div>
<div class="form-group">
<label for="password-confirm" class="col-md-4 control-label">Confirm Password</label>
<div class="col-md-6">
<input id="password-confirm" type="password" class="form-control" name="password_confirmation" required>
</div>
</div>
<div class="form-group">
<div class="col-md-6 col-md-offset-4">
<button type="submit" class="btn btn-primary">
Register
</button>
</div>
</div>
</form>
</div>
</div>
</div>-->
</div>
</div>
#endsection

How to show error and success message in laravel using version 5.2

I want to display my success and error message on my popup model i have setup session message for success and danger on my view but its redirecting me back to my page as there is condition in my controller but i want to show these success and error messages on my model:
My popup form:
<div class="modal-body">
<form role="form" id="passwordchangeform" class="common_form_style popup_form" method="POST" novalidate action="{{ url('/changepassword') }}">
<div class="row">
<div class="col-md-8 col-md-offset-2">
{{ csrf_field() }}
<div class="form-group">
<label for="password" style="width:100%">Původní heslo </label>
<input id="password" type="password" class="form-control" name="password">
<span toggle="#password-field" class="fa fa-fw fa-eye field-icon toggle-password"></span>
</div>
<div class="form-group">
<label for="new_password" style="width:100%">NovÄ› heslo</label>
<input id="new_password" type="password" class="form-control" name="new_password">
<span toggle="#password-field" class="fa fa-fw fa-eye field-icon toggle-password"></span>
<span class="help-block" style="color:#737373;font-size:14px;float:right;margin-right: 30px;font-weight: 100 !important;">MinimálnÄ› 8 znaků, jedno velké a malé písmeno a Äíslo</span>
</div>
<div class="form-group">
<label for="heslo znovu">Potvrzení heslo</label>
<input id="password_confirmation" type="password" class="form-control" name="password_confirmation">
<span toggle="#password-field" class="fa fa-fw fa-eye field-icon toggle-password"></span>
</div>
<div class="submit-btn text-center">
<button type="submit" class="btn btn-default chci" style="background:#e94549;">Uložit</button>
</div>
<div style="margin-top:10px;" id="success-messages"></div>
</div>
<div class="col-md-12 pull-right"></div>
</div>
</form>
</div>
and my controller:
$current_password = $user->password;
if(md5($request_data['password']) == $current_password) {
$user_id = $user->id;
$obj_user = User::find($user_id);
$obj_user->password = md5($request_data['new_password']);;
$obj_user->save();
$data = array('info_success' => "Password has been changed!", 'tab' => '');
return redirect('mujucet')->with($data);
} else {
$error = array('non-success' => "Heslo, které jste zadali, je neplatné.", 'tab' => '');
return redirect('mujucet')->with($error);
}
I want to show messages on my pop how i can do that
Your help need here!
The problem seems to be that nowhere within your view you're using the variables you're sending from the controller. Add this and it should function as expected:
//Assuming blade & bootstrap in this case:
#if(isset($info_success ))
<div class="col-xs-12">
<div class="alert alert-success">
<b>Success:</b>{{ $info_success }}
</div>
</div>
#elseif(isset($non_success))
<div class="col-xs-12">
<div class="alert alert-danger">
<b>Error:</b>{{ $non_success }}
</div>
</div>
#endif

php - submit button is not working in isset

I am trying to add a form in my html which will get 12 input box and save it to mysql. but its echoing failed as because of submit button perhaps. because in if for the isset submit button the else is forwarding message. Code for my html
<body class="templatemo-bg-image-2">
<div class="container">
<div class="col-md-12">
<form class="form-horizontal templatemo-contact-form-1" role="form" action="input.php" method="post">
<div class="form-group">
<div class="col-md-12">
<h1 class="margin-bottom-15">Marketing Samurai 2017</h1>
<h2 class="margin-bottom-15">Registration form</h2>
<p>This contact form is provided by templatemo that can be used for your websites. Credit goes to <a rel="nofollow" href="http://unsplash.com">Unsplash</a> for the background image.</p>
</div>
<hr>
<h4 class="margin-bottom-15">Team Info</h4>
<hr>
</div>
<div class="form-group">
<div class="col-md-12">
<label for="name" class="control-label">University Name</label>
<div class="templatemo-input-icon-container">
<i class="fa fa-university"></i>
<input name="uname" type="text" class="form-control" id="name" placeholder="">
</div>
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<label for="name" class="control-label">Team</label>
<div class="templatemo-input-icon-container">
<i class="fa fa-users"></i>
<input name="tname" type="text" class="form-control" id="name" placeholder="">
</div>
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<label for="name" class="control-label">Trix Id</label>
<div class="templatemo-input-icon-container">
<i class="fa fa-money"></i>
<input name="tcode" type="text" class="form-control" id="name" placeholder="Bkash transection Code">
</div>
</div>
</div>
<h4 class="margin-bottom-15">Leader Info</h4>
<hr>
<div class="form-group">
<div class="col-md-12">
<label for="name" class="control-label">Name</label>
<div class="templatemo-input-icon-container">
<i class="fa fa-user"></i>
<input name="lname" type="text" class="form-control" id="name" placeholder="">
</div>
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<label for="name" class="control-label">Email</label>
<div class="templatemo-input-icon-container">
<i class="fa fa-envelope-o"></i>
<input name="lmail" type="text" class="form-control" id="name" placeholder="">
</div>
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<label for="name" class="control-label">Contact</label>
<div class="templatemo-input-icon-container">
<i class="fa fa-phone"></i>
<input name="lcont" type="text" class="form-control" id="name" placeholder="">
</div>
</div>
</div>
<h4 class="margin-bottom-15">1st Member Info</h4>
<hr>
<div class="form-group">
<div class="col-md-12">
<label for="name" class="control-label">Name</label>
<div class="templatemo-input-icon-container">
<i class="fa fa-user"></i>
<input name="m1name" type="text" class="form-control" id="name" placeholder="">
</div>
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<label for="name" class="control-label">Email</label>
<div class="templatemo-input-icon-container">
<i class="fa fa-envelope-o"></i>
<input name="m1mail" type="text" class="form-control" id="name" placeholder="">
</div>
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<label for="name" class="control-label">Contact</label>
<div class="templatemo-input-icon-container">
<i class="fa fa-phone"></i>
<input name="m1cont" type="text" class="form-control" id="name" placeholder="">
</div>
</div>
</div>
<h4 class="margin-bottom-15">2nd Member Info</h4>
<hr>
<div class="form-group">
<div class="col-md-12">
<label for="name" class="control-label">Name</label>
<div class="templatemo-input-icon-container">
<i class="fa fa-user"></i>
<input name="m2name" type="text" class="form-control" id="name" placeholder="">
</div>
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<label for="name" class="control-label">Email</label>
<div class="templatemo-input-icon-container">
<i class="fa fa-envelope-o"></i>
<input name="m2mail" type="text" class="form-control" id="name" placeholder="">
</div>
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<label for="name" class="control-label">Contact</label>
<div class="templatemo-input-icon-container">
<i class="fa fa-phone"></i>
<input name="m2cont" type="text" class="form-control" id="name" placeholder="">
</div>
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<button type="submit" value="Submit" name="submit" class="btn btn-success pull-right">></button>
</div>
</div>
</form>
</div>
</div>
Code for php
<?php
$con = mysqli_connect('localhost','root','');
if(!$con){
echo 'Not Connected To Server';
}
if (!mysqli_select_db ($con,'test')) {
echo 'Database Not Selected';
}
if (isset($_POST['submit'])){
$uni = $_POST['uname'];
$team = $_POST['tname'];
$trix = $_POST['tcode'];
$leader = $_POST['lname'];
$lemail = $_POST['lmail'];
$leadercon = $_POST['lcont'];
$mname = $_POST['m1name'];
$memail = $_POST['m1mail'];
$mcon = $_POST['m1cont'];
$mname3 = $_POST['m2name'];
$memail3 = $_POST['m2mail'];
$mcon3 = $_POST['m2cont'];
$sql = "INSERT INTO 'memberdetails' (uninam, team, trixid, mem, mail, cont, mem1, mail1, con1, mem2, mail2, con2) VALUES ('$uni', '$team', '$trix', '$leader', '$lemail', '$leadercon', '$mname', '$memail', '$mcon', '$mname3', '$memail3', '$mcon3' )";
if (!mysqli_query($con,$sql))
{
echo 'Not Inserted';
}
else
{
echo 'Inserted Successfully';
}
header("refresh:2; url=index.html");
} else {
echo "failed";
}
I haven't made any validation yet. and I am trying with msqli and database, table is connecting then why the error is coming? I just made the submit button just to insert docs. whats should I do to prevent the fail message. Thanks in advance. :)
Submit must be <input> with name or it won't be available using $_POST['submit']
<input type="submit" value="Submit" name="submit" />
Try to remove "submit" text from name of form button and replace with another text
<button type="submit" value="Submit" name="form_sumit" class="btn btn-success pull-right">></button>

Categories