I added dropzone in a form in laravel and every single time I add the images the form immediately submits without me clicking on the submit button. Please refer to following codes:
Here are the codes from the dropzone vue component
<template>
<div class="container" ref="imageUpload">
<div class="row justify-content-center mb-3">
<div class="col-12 bg-dark text-white rounded py-3 my-2 text-center">
DROP IMAGE(S) HERE
</div>
</div>
</div>
</template>
<script>
import Dropzone from 'dropzone';
export default {
data: function () {
return{
dropzone: null
}
},
mounted() {
this.dropzone = new Dropzone(this.$refs.imageUpload, {
url: '/blog'
});
}
}
</script>
Here are the codes from the BlogsController.php:
public function store(Request $request)
{
if(! is_dir(public_path('blog_images'))){
mkdir(public_path('/blog_images'), 0777);
}
$blogimages = Collection::wrap( request()->file('file'));
$blogimages->each(function($blogimage){
$basename = Str::random();
$original = $basename . '.'. $blogimage->getClientOriginalExtension();
$blogimage->move(public_path('/blog_images'), $original);
Blog::create([
'original' => '/blog_images/' . $original,
]);
});
$blog = Blog::create($this->validateRequest());
return view('blog.index');
}
public function validateRequest()
{
return request()->validate([
'title' => 'required',
'caption' => 'required',
]);
}
Here are the codes from the create.blade.php which contains the form:
<div class="container mt-5 blog-body">
<form action="/blog" method="POST" enctype="multipart/form-data">
<div class="form-group row">
<label for="title" class="col-4 col-form-label">Blog Title</label>
<div class="col-8">
<input id="title" type="text" class="form-control #error('title') is-invalid #enderror" name="title"
value="{{old('title') }}" autocomplete="title" placeholder="Title">
<div class="text-danger">{{ $errors->first('title') }}</div>
</div>
</div>
<div class="form-group row">
<label for="caption" class="col-4 col-form-label">Blog Caption</label>
<div class="col-8">
<input id="caption" type="text" class="form-control #error('caption') is-invalid #enderror" name="caption"
value="{{old('caption') }}" autocomplete="caption" placeholder="caption">
<div class="text-danger">{{ $errors->first('caption') }}</div>
</div>
</div>
<div class="form-group row">
<label class="col-4 col-form-label">Blog Images</label>
<div class="col-8" id="app">
<dropzone-component></dropzone-component>
</div>
</div>
<button type="submit" class="btn btn-primary"> Post Blog</button>
#csrf
</form>
Here are the codes from the web.php file:
Route::resource('blog', 'BlogsController');
Here are the codes from the create_blogs_table.php
Schema::create('blogs', function (Blueprint $table) {
$table->id();
$table->timestamps();
$table->string('original');
$table->string('title');
$table->string('caption');
});
You can set the options:
autoProcessQueue: false
parallelUploads: 10
So the dropzone does not upload immediately.
Related
I have a view where I pull the data with an "onclick" of the "Asisgnar" button and when I click on the "Enviar formulario" button, an email is sent directly with the loaded data... this works perfectly, but I would like it to be sent the mail without redirecting me to another page.
My form code
<form action="{{route('contactanos.store')}}" method="POST">
{{ csrf_field() }}
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group">
<label for="inspector">Inspector</label>
<select class="form-select col-xs-12 col-sm-12 col-md-12" aria-label="Default select example" id="inspector" for="inspector" name="inspector" >
<option selected></option>
#foreach($users as $user)
<option value="{{ $user->name }}">{{ $user->name }}</option>
#endforeach
</select>
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-12">
<label for="estado">Estado</label>
<select class="form-select col-xs-12 col-sm-12 col-md-12" aria-label="Default select example" id="estado" for="estado" name="estado">
<option selected></option>
<option value="Pendiente">Pendiente</option>
<option value="Coordinado">Coordinado</option>
<option value="Peritando">Derivado a inspector</option>
<option value="Baja">Baja</option>
</select>
</div>
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group">
<label for="localidad">Localidad</label>
<input type="text" name="localidad" id="localidad" class="form-control" >
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group">
<label for="fechaip">Fecha IP</label>
<input type="date" name="fechaip" id="fechaip" class="form-control" >
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group">
<label for="siniestro">Siniestro</label>
<input type="text" name="siniestro" id="siniestro" class="form-control" >
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group">
<label for="inspector">Inspector</label>
<select class="form-select col-xs-12 col-sm-12 col-md-12" aria-label="Default select example" id="emailperito" for="emailperito" name="emailperito" >
<option selected></option>
#foreach($users as $user)
<option value="{{ $user->email }}">{{ $user->name }}</option>
#endforeach
</select>
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group">
<label for="email">Email taller</label>
<input type="text" name="email" id="email" class="form-control" >
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group">
<label for="patente">Patente</label>
<input type="text" name="patente" id="patente" class="form-control" >
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group">
<label for="modalidad">Tipo de inspección</label>
<input type="text" name="modalidad" id="modalidad" class="form-control" >
</div>
</div>
<input type="hidden" id="id">
<button type="submit" id="updateButton" class="btn btn-success" onclick="updateData(event)">Guardar</button>
<button type="submit" class="btn btn-primary float-right">Enviar formulario</button>
</form>
Controller Code to send mail
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
//mail
use App\Mail\ContactanosMailable;
use Illuminate\Support\Facades\Mail;
use App\Models\Siniestro;
class CoordinacionesController extends Controller
{
public function index(){
return view('contactanos.index');
}
public function store(Request $request){
$siniestro = Siniestro::paginate(1000);
$this->siniestro = $siniestro;
$email = $this->siniestro['emailperito'];
$cc = $this->siniestro['email'];
$correo = new ContactanosMailable($request->all());
Mail::to($email)->cc($cc)->send($correo);
return redirect()->route('siniestros.index');
}
}
View.blade
My view
I have tried removing the post method and removing the "return redirect()->route('sinisters.index');" of the controller, but it doesn't work.
you can do it with an ajax like this
$.ajax({
url: '{{route("your-route")}}',
method: "POST",
data: {
_token: '<?php echo csrf_token() ?>',
... // the rest of your form
}
})
Try this solution
add jquery in your blade file
jquery cdn
<script src="https://code.jquery.com/jquery-3.6.0.min.js" crossorigin="anonymous"></script>
Give class to your form
<form action="{{route('contactanos.store')}}" method="POST" class="my_form">
Change your javascript code as per below
$(document).on('submit', '.my_form', function (event) {
event.preventDefault();
var form = $(this);
$.ajax({
type: form.attr('method'),
url: form.attr('action'),
data: form.serialize(),
success: function (response) {
if(response.success){
//handle success message
} else {
//handle error message
}
},
error: function (xhr, textStatus, errorThrown) {
console.log("ERROR");
}
});
});
change your controller->store function
public function store(Request $request){
try {
$siniestro = Siniestro::paginate(1000);
$this->siniestro = $siniestro;
$email = $this->siniestro['emailperito'];
$cc = $this->siniestro['email'];
$correo = new ContactanosMailable($request->all());
Mail::to($email)->cc($cc)->send($correo);
return response()->json([
'success' => true,
'message' => 'Your success message'
]);
} catch (\Throwable $th) {
return response()->json([
'success' => false,
'message' => 'Your error message'
]);
}
}
iam new in laravel i have problem to add data in data base using laravel , i get only validation response in form but after i submit data i don't get any response only just page refresh . without any message appear in view
ac any on help me ?
this is man categories request for validation
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class MaincategoryRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* #return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* #return array
*/
public function rules()
{
return [
'id' => 'integer|required',
'name' => 'min:2|required|max:50|unique:category_translations',
'slug' => 'required|unique:categories,slug,'.$this->id,
'url' => 'required|url',
'status' => 'integer'
];
}
// validation messages
public function messages()
{
return [
'id.required'=>trans('dashboard\validate.required'),
'id.integer'=>trans('dashboard\validate.integer'),
'id.exists'=>trans('dashboard\validate.exists'),
'name.required'=>trans('dashboard\validate.required'),
'name.min'=>trans('dashboard\validate.min'),
'name.max'=>trans('dashboard\validate.max'),
'name.unique'=>trans('dashboard\validate.unique'),
'slug.required'=>trans('dashboard\validate.required'),
'slug.min'=>trans('dashboard\validate.min'),
'slug.max'=>trans('dashboard\validate.max'),
'slug.unique'=>trans('dashboard\validate.unique'),
'url.active_url'=>trans('dashboard\validate.url'),
'url.required'=>trans('dashboard\validate.required'),
'status.integer'=>trans('dashboard\validate.integer'),
];
}
}
this is my route in details
Route::get('create','MainCategoriesController#create') -> name('maincategories.create');
Route::post('store','MainCategoriesController#store') -> name('maincategories.store');
this is my controller in details
public function store(MaincategoryRequest $request )
{
try{
DB::beginTransaction();
// prepare data
$validatedData = array(
'name' =>$request->name,
'url' =>$request->url,
'slug' =>$request->slug,
'last_updated_by' =>auth('admin')->user()->id,
'created_by' =>auth('admin')->user()->id,
'created' =>time(),
);
//check if status is sent
$request->has('status') ? $validatedData['status'] = 1: $validatedData['status'] = 2;
// check if category is exist
$add = Category::create($validatedData);
if (!$add){
return redirect()->route('maincategories.create')->with(['error'=> trans('dashboard\messages.addfailed')]);
}
// start add translated data
$add->name=$request->name;
$add->save();
return redirect()->back()->with('success',trans('dashboard\messages.save'));
DB::commit();
}catch (\Exception $ex){
return redirect()->back()->with('error',trans('dashboard\messages.addfailed'));
DB::rollBack();
}
}
this is my view in details
#extends('layouts.admin')
#section("title",trans('dashboard\category.title-add'))
#section('content')
<div class="app-content content">
<div class="content-wrapper">
<div class="content-header row">
<div class="content-header-left col-md-6 col-12 mb-2">
<div class="row breadcrumbs-top">
<div class="breadcrumb-wrapper col-12">
<ol class="breadcrumb">
<li class="breadcrumb-item"> {{trans('dashboard\messages.home')}}
</li>
<li class="breadcrumb-item active">{{trans('dashboard\category.title-add')}}
</li>
</ol>
</div>
</div>
</div>
</div>
<div class="content-body">
<!-- Basic form layout section start -->
<section id="basic-form-layouts">
<div class="row match-height">
<div class="col-md-12">
<div class="card">
<div class="card-header">
<h4 class="card-title" id="basic-layout-form"> {{trans('dashboard\category.title-add')}} </h4>
<a class="heading-elements-toggle"><i
class="la la-ellipsis-v font-medium-3"></i></a>
<div class="heading-elements">
<ul class="list-inline mb-0">
<li><a data-action="collapse"><i class="ft-minus"></i></a></li>
<li><a data-action="reload"><i class="ft-rotate-cw"></i></a></li>
<li><a data-action="expand"><i class="ft-maximize"></i></a></li>
<li><a data-action="close"><i class="ft-x"></i></a></li>
</ul>
</div>
</div>
#include('dashboard.includes.alerts.success')
#include('dashboard.includes.alerts.errors')
<div class="card-content collapse show">
<div class="card-body">
<form class="form"
action="{{route('maincategories.store')}}"
method="post"
enctype="multipart/form-data">
#csrf
<div class="form-body">
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label for="projectinput1"> {{trans('dashboard\category.name')}} </label>
<input type="text" value="{{old('name')}}"
id="name"
class="form-control"
placeholder=" "
name="name">
#error("name")
<span class="text-danger">{{$message}}</span>
#enderror
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="projectinput1"> {{trans('dashboard\category.slug')}} </label>
<input type="text"
value="{{old('slug')}}"
id="email"
class="form-control"
placeholder=" "
name="slug">
#error("slug")
<span class="text-danger">{{$message}}</span>
#enderror
</div>
</div>
<div class="col-md-12">
<div class="form-group">
<label for="projectinput1"> {{trans('dashboard\category.url')}} </label>
<input type="text"
value="{{old('url')}}"
id="plain_value"
class="form-control"
placeholder=" "
name="url">
#error("url")
<span class="text-danger">{{$message}}</span>
#enderror
</div>
</div>
</div>
</div>
<div class="col-md-12">
<div class="form-group">
<label> {{trans('dashboard\category.image')}} </label>
<label id="projectinput7" class="file center-block">
<input type="file" id="file" name="image">
<span class="file-custom"></span>
</label>
#error('image')
<span class="text-danger">{{$message}}</span>
#enderror
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="form-group mt-1">
<input type="checkbox" value="1"
name="status"
id="switcheryColor4"
class="switchery" data-color="success"
checked />
<label for="switcheryColor4"
class="card-title ml-1">{{trans('dashboard\messages.status')}} </label>
#error("status")
<span class="text-danger"> </span>
#enderror
</div>
</div>
</div>
<div class="form-actions">
<button type="button" class="btn btn-warning mr-1"
onclick="history.back();">
<i class="ft-x"></i> {{trans('dashboard\messages.back')}}
</button>
<button type="submit" class="btn btn-primary">
<i class="la la-check-square-o"></i> {{trans('dashboard\messages.save')}}
</button>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</section>
<!-- // Basic form layout section end -->
</div>
</div>
</div>
#stop
#section('script')
<script >
$(document).ready(function() {
//start update password
$("#EditPassword").submit(function(){
var formData = $(this).serialize();
var allData = formData + "&action=editPass";
$('#repassword_error').text('');
$('#password_error').text('');
$.ajax({
url: "{{url("admin/category/update_password/{id}")}}",
type:"PUT",
data: allData, // Data sent to server, a set of key/value pairs (i.e. form fields and values)
beforeSend:function(){
//alert(allData)
},
statusCode: {
404: function() {
alert( "page not found" );
},
},
success:function(valdata) {
//alert(valdata);
//alert("")
if(valdata.status == "success")
{
$("#updatePasswordResult").html(valdata.message);
setTimeout(function(){$('#changepassword').modal('hide');}, 2000);
}else{
$("#updatePasswordResult").html(valdata.message);
}
},
error: function (reject) {
var response = $.parseJSON(reject.responseText);
$.each(response.errors, function (key, val) {
$("#" + key + "_error").text(val[0]);
});
}
});
return false;
});
});
</script>
#stop
You don't need to use transaction here, However, move DB::commit before return .
besides, check $guarded and $fillable in your model.
also you can dd($ex->getMessage()) to track the error.
I wish to be able to edit my users through the admin panel but this returns the following error to me:
Trying to get property 'id' of non-object
it will be an error in my view with the call of the variable ID if I change it I have the same thing with my variable name.
I use the users table and in no other place in my code do I have problems
help me please
URI : /role-edit/{id}
View :
<div class="container">
<div class="row">
<div class="col-md-12">
<div class="card">
<div class="card-header">
<h4>Edit register roles</h4>
</div>
<div class="card-body">
<form action="/role-register-update/{{ $users->id }}" method="POST">
{{ csrf_field() }}
{{ method_field('PUT') }}
<div class="form-group">
<label>Name</label>
<input type="text" name="name" value="{{ $users->name }}" class="form-control">
</div>
<div class="form-group">
<label>Give role</label>
<select name="type" class="form-control">
<option value="admin">Admin</option>
<option value="vendor">Vendor</option>
<option value="">None</option>
</select>
<button type="submit" class="btn btn-success">Update</button>
Cancel
</div>
</form>
</div>
</div>
</div>
</div>
</div>
Controller :
class DashboardController extends Controller
{
public function registered()
{
$users = User::all();
return view('admin.registeradmin')->with('users', $users);
}
public function edit(Request $request,$id)
{
$users = User::findOrFail($id);
return view('admin.edit-register')->with('users',$users);
}
public function update(Request $request, $id)
{
$users = User::findOrFail($id);
$users->name = $request->input('name');
$users->usertype = $request->input('type');
$users->update();
return redirect('/role-register')->with('status', 'You data is update');
}
public function destroy($id)
{
$users = User::where('id', $id);
if ($users != null)
{
$users->delete();
return redirect('/role-register')->with('status', 'User is correctly deleted !');
}
return redirect('/role-register')->with('status', 'User is not correctly deleted !');
}
}
Routes :
Route::get('/', function () {
return view('pages.home');
});
Route::get('/aboutus', function () {
return view('pages.aboutus');
})->name('aboutus');
Auth::routes();
Route::get('profile', 'UserProfileController#show')->middleware('auth')->name('profile.show');
Route::post('profile', 'UserProfileController#update')->middleware('auth')->name('profile.update');
Route::get('/home', 'HomeController#index')->name('home');
Route::group(['middleware' => ['auth', 'admin']], function () {
Route::get('/dashboard', function () {
return view('admin.dashboard');
});
Route::get('/role-register', 'Admin\DashboardController#registered');
Route::get('/role-edit/{id}', 'Admin\DashboardController#edit');
Route::put('/role-register-update/{id}', 'Admin\DashboardController#update');
Route::delete('/role-delete/{id}', 'Admin\DashboardController#destroy');
});
Add dd($users) in the edit function of your controller. If you get the data, add the following to the form action form action:
{{route('routename',['id'=>$users->id])}}
// Controller
public function Updateprofile(Request $request)
{
if (Auth::check() && Auth::user()->role->id == 2) {
$this->validate($request, [
'name' => 'required',
'email' => 'required|email'
]);
$image = $request->file('image');
$slug = str_slug($request->name);
if (isset($image))
{
$currentDate = Carbon::now()->toDateString();
$imagename = $slug.'-'.$currentDate.'-'. uniqid() .'.'. $image->getClientOriginalExtension();
$image_resize = Image::make($image->getRealPath());
$image_resize->resize(600,500);
if (!file_exists('storage/uploads/profile'))
{
mkdir('storage/uploads/profile',0777,true);
}
unlink('storage/uploads/profile/'.Auth::user()->image);
$image_resize->save('storage/uploads/profile/'.$imagename);
}else{
$imagename = Auth::user()->image;
}
$user = User::find(Auth::id());
$user->name = $request->name;
$user->email = $request->email;
$user->image = $imagename;
$user->save();
Toastr::success('Profile Successfully Updated :)', 'Success');
return redirect()->back();
}
}
// blade file
<form method="POST" action="{{route('user.profile.update')}}" class="form-horizontal" enctype="multipart/form-data">
#csrf
#method('PUT')
<div class="row clearfix">
<div class="col-lg-2 col-md-2 col-sm-4 col-xs-5 form-control-label">
<label for="name">Name : </label>
</div>
<div class="col-lg-10 col-md-10 col-sm-8 col-xs-7">
<div class="form-group">
<div class="form-line">
<input type="text" id="name" class="form-control" placeholder="Enter your name" name="name" value="{{Auth::user()->name}} {{old('name')}}">
</div>
</div>
</div>
</div>
<div class="row clearfix">
<div class="col-lg-2 col-md-2 col-sm-4 col-xs-5 form-control-label">
<label for="image">{{__('Image')}} : </label>
</div>
<div class="col-lg-10 col-md-10 col-sm-8 col-xs-7">
<div class="form-group">
<div class="form-line">
<input type="file" name="image" >
</div>
</div>
</div>
</div>
<div class="row clearfix">
<div class="col-lg-2 col-md-2 col-sm-4 col-xs-5 form-control-label">
<label for="email_address_2">Email Address</label>
</div>
<div class="col-lg-10 col-md-10 col-sm-8 col-xs-7">
<div class="form-group">
<div class="form-line">
<input type="text" id="email_address_2" class="form-control" value="{{Auth::user()->email}} {{old('email')}}" placeholder="Enter your email address" name="email" ">
</div>
</div>
</div>
<div class="row clearfix">
<div class="col-lg-offset-2 col-md-offset-2 col-sm-offset-4 col-xs-offset-5">
<button type="submit" class="btn btn-primary m-t-15 waves-effect">UPDATE</button>
</div>
</div>
</form>
I am using the Croppie script to edit images before uploading to my server.
https://foliotek.github.io/Croppie/
The problem is Croppie encodes the cropped image in a base64 format. I have created a hidden input and attached the base64 string. I need to know how to grab the string so i can decode it and post it with my form.
I have tried so many methods but i am stuck. Any help will be appreciated
Controller
$post = new Post;
$post->post_category_id = $request->post_category_id;
$post->title = $request->title;
$post->body = $request->body;
$post->meta_description = $request->meta_description;
$post->slug = $request->slug;
$post->user_id = auth()->id();
$image = $request->input('featimage'); // image base64 encoded
preg_match("/data:image\/(.*?);/",$image,$image_extension); // extract the image extension
$image = preg_replace('/data:image\/(.*?);base64,/','',$image); // remove the type part
$image = str_replace(' ', '+', $image);
$imageName = 'image_' . time() . '.' . $image_extension[1]; //generating unique file name;
\Storage::disk('public')->put($imageName,base64_decode($image)
$post->save();
}
View
<form class="form-horizontal" action="{{route('posts.store')}}" method="POST" enctype="multipart/form-data">
{{ csrf_field() }}
<fieldset>
<div class="form-group row"><label class="col-md-2 col-form-label">Title</label>
<div class="col-md-10"><input class="form-control" name="title" type="text"><span class="form-text">Please insert a title <small>eg. Exciting new event coming to London</small>
</span></div>
</div>
</fieldset>
<fieldset class="">
<div class="form-group row"><label class="col-md-2 col-form-label">Category</label>
<div class="col-md-10"><select name="post_category_id" class="custom-select custom-select-sm">
#foreach($postCategories as $postCategory)
<option value="{{ $postCategory->id }}">{{ $postCategory->name }}</option>
#endforeach
</select></div>
</div>
</fieldset>
<fieldset>
<div class="form-group row"><label class="col-md-2 col-form-label">Post Body</label>
<div class="col-md-10">
<textarea type="textarea" class="form-control" rows="10" name="body"></textarea>
</div>
</div>
</fieldset>
<fieldset>
<div class="form-group row"><label class="col-md-2 col-form-label">Meta Description</label>
<div class="col-md-10">
<textarea type="textarea" class="form-control" rows="4" name="meta_description"></textarea>
</div>
</div>
</fieldset>
<fieldset>
<select name="tags[]" multiple="multiple" class="form-control select2-multi">
#foreach($tags as $tag)
<option value="{{ $tag->id }}">{{ $tag->name }}</option>
#endforeach
</select>
</fieldset>
</div>
</div><!-- END card-->
</div>
<div class="col-md-4">
<div class="card card-default">
<div class="card-header">Featured Image</div>
<div class="card-body">
<fieldset>
<figure>
<img src="" class="gambar img-responsive img-thumbnail" id="item-img-output" /></figure>
<input type="hidden" id="featimage" name="featimage">
</fieldset>
<input type="file" class="item-img file center-block" name="upload"/>
</label>
</div>
<div>
</div>
<!-- START card-->
<div class="card card-default">
<div class="card-header">Slug</div>
<div class="card-body">
<div class="input-group mb-3">
<div class="input-group-prepend"><span class="input-group-text" id="basic-addon1">www.sixmedia.co.uk/</span></div><input class="form-control" name="slug" type="text" placeholder="slug" aria-label="Username" aria-describedby="basic-addon1">
</div>
</div>
</div><!-- END card-->
<!-- START card-->
<div class="card card-default">
<div class="card-header">Featured</div>
<div class="card-body">
<div class="col-md-12">
<fieldset>
<div class="form-group row">
#foreach($featured as $feat)
<div class="checkbox c-checkbox"><label><input name="featured[]" type="checkbox" value="{{$feat->id}}"><span class="fa fa-check"></span>{{ $feat->name }} </label></div>
#endforeach
</div>
</fieldset>
</div>
</div>
</div><!-- END card-->
<button class="btn btn-primary btn-block" name="submit">Save</button>
<button class="btn btn-danger btn-block" name="submit">Cancel</button>
</form>
JS
<script type="text/javascript">
$(".gambar").attr("src", "http://www.pngall.com/wp-content/uploads/2/Upload-PNG-Image-File.png");
var $uploadCrop,
tempFilename,
rawImg,
imageId;
function readFile(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
$('.upload-demo').addClass('ready');
$('#cropImagePop').modal('show');
rawImg = e.target.result;
}
reader.readAsDataURL(input.files[0]);
}
else {
swal("Sorry - you're browser doesn't support the FileReader API");
}
}
$uploadCrop = $('#upload-demo').croppie({
viewport: {
width: 500,
height: 281,
},
enforceBoundary: false,
enableExif: true
});
$('#cropImagePop').on('shown.bs.modal', function(){
// alert('Shown pop');
$uploadCrop.croppie('bind', {
url: rawImg
}).then(function(){
console.log('jQuery bind complete');
});
});
$('.item-img').on('change', function () { imageId = $(this).data('id'); tempFilename = $(this).val();
$('#cancelCropBtn').data('id', imageId); readFile(this); });
$('#cropImageBtn').on('click', function (ev) {
$uploadCrop.croppie('result', {
type: 'base64',
format: 'png',
size: {width: 350, height: 200}
}).then(function (resp) {
$('#item-img-output').attr('src', resp);
$('#featimage').attr('src', resp);
$('#cropImagePop').modal('hide');
});
});
// End upload preview image
</script>
The problem seems to be in your jquery script, you are setting the base64 string as the source of <input type="hidden" id="featimage">
change this:
$('#featimage').attr('src', resp);
to this
`$('#featimage').val(resp);`
Admin login don't work and don't give me any error.
I have this routes in web.php file:
Auth::routes();
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#getIndex')->name('admin.dashboard');
Route::get('/logout','Auth\AdminLoginController#logout')->name('admin.logout');
Route::post('/password/email','Auth\AdminForgotPasswordController#sendResetLinkEmail')->name('admin.password.email');
Route::get('/password/reset','Auth\AdminForgotPasswordController#showLinkRequestForm')->name('admin.password.request');
Route::post('/password/reset','Auth\AdminResetPasswordController#reset');
Route::get('/password/reset/{token}','Auth\AdminResetPasswordController#showResetForm')->name('admin.password.reset');
});
And this functions in controller(I only put here which have the problems)
public function showLoginForm()
{
return view('auth.adminlogin');
}
public function login(Request $request)
{
//validate the form data
$this->validate($request, [
'email' => 'required|email',
'password' => 'required|min:6'
]);
//attempt to log the user in
if (Auth::guard('admin')->attempt(['email' => $request->email, 'password' => $request->password], $request->remember)){
//if successful, then redirect to their intended location
return redirect('/admin');
}
return redirect()->back()->withInput($request->only('email','remember'));
}
And in resources/views/auth/adminlogin.blade.php i have this code:
#extends('backend.public.includes.head')
<body>
<div class="container">
<div class="row">
<div class="col-md-8 col-md-offset-2">
<div class="panel panel-default">
<div class="panel-heading">ADMIN Login</div>
<div class="panel-body">
<form class="form-horizontal" role="form" method="POST" action="{{ route('admin.login.submit') }}">
{{ csrf_field() }}
<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 autofocus>
#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">
<div class="col-md-6 col-md-offset-4">
<div class="checkbox">
<label>
<input type="checkbox" name="remember" {{ old('remember') ? 'checked' : '' }}> Remember Me
</label>
</div>
</div>
</div>
<div class="form-group">
<div class="col-md-8 col-md-offset-4">
<button type="submit" class="btn btn-primary">
Login
</button>
<a class="btn btn-link" href="{{ route('admin.password.request') }}">
Forgot Your Password?
</a>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</body>
This was working days ago.. and now not, i'm looking all but don't find the error. In networking isn't showing anything and with a debug i don't see anything.
I try to reset password and when i reset it (i have a redirect in the function he redirect me good, only not working in normal login).
Errors aren't showed too
EDIT
Migrate file:
public function up()
{
Schema::create('admins', function (Blueprint $table) {
$table->increments('id');
$table->string('name',50)->unique();
$table->string('email',200)->unique();
$table->string('password');
$table->boolean('public')->default(true);
$table->rememberToken();
$table->timestamps();
});
}
Seed file:
private $arrayAdmins = array(
array(
'name' => 'Lluis',
'email' => 'lluis.puig#correo.biz',
'password' => 'correo1',
'public' => 1
)
);
public function run()
{
self::seedAdmins();
}
public function seedAdmins()
{
DB::table('admins')->delete();
foreach ($this->arrayAdmins as $admin)
{
$a = new Admin;
$a->name = $admin['name'];
$a->email = $admin['email'];
$a->password = $admin['password'];
$a->public = $admin['public'];
$a->save();
}
}
The admin login isn't working if i created with the seed. (So the problem i guess is with the "user created" with the seed.
I try to create one with php artisan tinker and it works.
SOLVED
I check the seed. The problem was de password isn't encrypted!
This line :
$a->password = $admin['password'];
Must be like this:
$a->password = bcrypt($admin['password']);