I encountered an issue with the route as follows.
Route [forgotpassword/reset] not defined.
Login forgotpassword url
<div class="forgot-password">Forgot password?</div>
Route code
Route::group(['namespace' => 'Auth'], function() {
Route::get('/forgotpassword/reset', 'ForgotPasswordController#showLinkRequestForm');
Route::post('/forgotpassword/email', 'ForgotPasswordController#sendResetLinkEmail');
Route::get('/password/reset/{token}', 'ResetPasswordController#showResetForm');
Route::post('/password/reset', 'ResetPasswordController#reset');
});
ForgotPasswordController Code
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Base\BaseController;
use Illuminate\Foundation\Auth\SendsPasswordResetEmails;
class ForgotPasswordController extends BaseController
{
use SendsPasswordResetEmails;
/**
* Create a new controller instance.
*
* #return void
*/
public function __construct()
{
$this->middleware('guest');
}
public function showLinkRequestForm()
{
return view('password.forgotpassword');
}
}
I overwrite function ShowLink to return view into my forgotPassword blade.
and here's my forgotPassword blade
#extends('layout.master')
#section('content')
<div id="content" class="content">
#include('partials.breadcrumbs')
<h1 class="page-header">Change <small>password</small></h1>
#include('partials.message')
<div class="row">
<div class="col-md-12">
<div class="panel panel-inverse" data-sortable-id="ui-general-1">
<div class="panel-heading">
<h2 class="panel-title">Change Password</h2>
</div>
<div class="panel-body">
{!! Form::open(['method' => 'forgotpassword','route' => ['forgotpassword/reset']]) !!}
<div class="forgot-password-form">
#if (Session::has('message'))
<div class="col-sm-12">
<div class="alert alert-success">
{{ Session::get('message') }}
</div>
</div>
#endif
{!! csrf_field() !!}
<div class="row ct-no-margin">
<div class="col-sm-4 col-xs-12">
<div class="form-group">
<div class="{{ $errors->has('email') ? ' has-error' : '' }}">
<div class="row ct-no-margin">
<div class="col-sm-12 ct-no-padding">
<label for="">Email address</label>
</div>
<div class="col-sm-12 ct-no-padding">
<input type="email" name="email" class="form-control" required/>
</div>
#if ($errors->has('email'))
<span class="help-block error-email">
<strong>{{ $errors->first('email') }}</strong>
</span>
#endif
</div>
</div>
</div>
<div class="form-group">
<button type="submit" class="btn fp-submit-btn">Submit</button>
Cancel
</div>
</div>
</div>
</form>
</div>
</div>
</section>
</div>
#endsection
Any help in this regard will be appreciated
Change your route to named route like:
Route::get('/forgotpassword/reset', [ 'as' => 'forgotpassword/reset', 'uses' => 'ForgotPasswordController#showLinkRequestForm']);
And as of your view file I found this:
{!! Form::open(['method' => 'forgotpassword','route' => ['forgotpassword/reset']]) !!}
Use 'method' => 'get'
Related
I'm new with Laravel 8, I have been trying uploading a form with a file field but I keep getting an error "image must be an image", even though I have enctype='multipart/form-data' included in a form.
Blade Template
#extends('layouts.app')
#section('contents')
<div class="container">
<h1> Create a Posts</h1>
{!! Form::open(['action' =>['App\Http\Controllers\PostController#store','enctype'=>'multipart/form-data', 'method'=>'POST']]) !!}
<div class="form-group">
{{Form::label('title', 'Title')}}
{{Form::text('title','',['class'=>'form-control','placeholder'=>'Title'])}}
</div>
<div class="form-group">
{{Form::label('body', 'Body')}}
{{Form::textarea('body','',['class'=>'form-control','id'=>'article-ckeditor','placeholder'=>'Bodytext'])}}
</div>
<br>
<div class="form-group">
<div class="image">
{{Form::file('cover_image')}}
</div>
</div>
<br>
{{Form::submit('Submit',['class'=>'btn btn-primary']);}}
{!! Form::close() !!}
</div>
#endsection
Controller
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\Post;
use App\Models\User;
public function store(Request $request)
{
$validatedData = $request->validate([
'title' => ['required', 'unique:posts', 'max:500000'],
'body' => ['required'],
'cover_image'=>['image','nullable','max:19999']
]);
//handle file uploads
if($request->hasfile('cover_image')){
return '123';
}
}
Route
Route::resource('/post', PostController::class);
You need to allow file uploads when you open the form :
#extends('layouts.app')
#section('contents')
<div class="container">
<h1> Create a Posts</h1>
{!! Form::open(['action' =>['App\Http\Controllers\PostController#store','enctype'=>'multipart/form-data', 'method'=>'POST',
// add files true in the form open
'files' => true]]) !!}
<div class="form-group">
{{Form::label('title', 'Title')}}
{{Form::text('title','',['class'=>'form-control','placeholder'=>'Title'])}}
</div>
<div class="form-group">
{{Form::label('body', 'Body')}}
{{Form::textarea('body','',['class'=>'form-control','id'=>'article-ckeditor','placeholder'=>'Bodytext'])}}
</div>
<br>
<div class="form-group">
<div class="image">
{{Form::file('cover_image')}}
</div>
</div>
<br>
{{Form::submit('Submit',['class'=>'btn btn-primary']);}}
{!! Form::close() !!}
</div>
#endsection
see https://laravelcollective.com/docs/6.x/html#opening-a-form
I want to copy values from row from one table (proforms), to row in another table (invoices) using button in view. But getting error: Method Illuminate\Database\Eloquent\Collection::create does not exist.
On line: 'grosstotal' => $proform->grosstotal,
This is my controller method:
public function duplicate(Request $request)
{
$proform = $this->proform->findOrFail($request->duplicate);
$invoice = Invoice::all();
//something like this
$duplicated = $invoice->create([
'invoicenumber' => $proform->proformnumber,
'invoicedate' => $proform->proformdate,
'selldate' => $proform->selldate,
'user_id' => $proform->user_id,
'form_id' => $proform->form_id,
'currency_id' => $proform->currency_id,
'paymentmethod' => $proform->paymentmethod,
'paymentdate' => $proform->paymentdate,
'status' => $proform->status,
'comments' => $proform->comments,
'city' => $proform->city,
'autonumber' => $proform->autonumber,
'automonth' => $proform->automonth,
'autoyear' => $proform->autoyear,
'name' => $proform->name,
'PKWIU' => $proform->PKWIU,
'quantity' => $proform->quantity,
'unit' => $proform->unit,
'netunit' => $proform->netunit,
'nettotal' => $proform->nettotal,
'VATrate' => $proform->VATrate,
'grossunit' => $proform->grossunit,
'grosstotal' => $proform->grosstotal,
]);
return redirect()->route('invoices.show', ['invoice' => $duplicated]);
}
This is my view with button for duplicate:
#extends('layouts.app')
#section('content')
<div class="row">
<div class="col-lg-12 margin-tb">
<div class="pull-left">
<h2>Szczegóły abonamentu</h2>
</div>
<div class="pull-right">
<a class="btn btn-primary" href="{{ route('proforms.index') }}"> Wstecz</a>
</div>
</div>
</div>
<div class="col-md-4">
<form action="{{ route('proforms.duplicate') }}" method="POST">
#csrf
<div class="input-group">
<input type="text" value="1" name="duplicate" class="form-control" readonly>
<span class="input-group-prepend">
<button type="submit" class="btn btn-primary">Wystaw fakturę</button>
</span>
</div>
</form>
</div>
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group">
<strong>Data wystawienia:</strong>
{{ $proform->proformdate }}
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group">
<strong>Kontrahent:</strong>
{{ $proform->user_id }}
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group">
<strong>Data sprzedaży:</strong>
{{ $proform->selldate }}
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group">
<strong>Termin płatności:</strong>
{{ $proform->paymentdate }}
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group">
<strong>Forma płatności:</strong>
{{ $proform->paymentmethod }}
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group">
<strong>Miejsce wystawienia:</strong>
{{ $proform->city }}
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group">
<strong>Status:</strong>
{{ $proform->status }}
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group">
<strong>Uwagi:</strong>
{{ $proform->comments }}
</div>
</div>
<div class="pull-left" style="margin: 15px;">
<h3>Pozycje proformy</h3>
</div>
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group">
<strong>Nazwa towaru lub usługi:</strong>
{{ $proform->name }}
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group">
<strong>PKWiU:</strong>
{{ $proform->PKWIU }}
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group">
<strong>Ilość:</strong>
{{ $proform->quantity }}
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group">
<strong>Jednostka:</strong>
{{ $proform->unit }}
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group">
<strong>Cena netto jednostki:</strong>
{{ $proform->netunit }}
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group">
<strong>Netto razem:</strong>
{{ $proform->nettotal }}
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group">
<strong>Stawka VAT:</strong>
{{ $proform->VATrate }}
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group">
<strong>Brutto jednostka:</strong>
{{ $proform->grossunit }}
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group">
<strong>Brutto razem:</strong>
{{ $proform->grosstotal }}
</div>
</div>
</div>
#endsection
This is my routes
<?php
use Illuminate\Support\Facades\Route;
Route::get('/', function(){
return view('welcome');
});
Route::get('home');
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
Auth::routes();
Route::get('/home', 'HomeController#index')->name('home');
Route::group(['middleware' => ['auth']], function () {
Route::get('/search', 'UserController#search');
Route::get('/search2', 'ProductController#search2');
Route::get('/search3', 'ProformController#search3');
Route::get('/search4', 'InvoiceController#search4');
Route::post('/duplicate', 'ProformController#duplicate')->name('proforms.duplicate');
Route::get('data', 'UserController#index');
Route::get('posts', 'PostController#index');
Route::get('/prodview', 'TestController#prodfunct');
Route::resource('roles', 'RoleController');
Route::resource('users', 'UserController');
Route::resource('permissions', 'PermissionController');
Route::resource('products', 'ProductController');
Route::resource('invoices', 'InvoiceController');
Route::resource('category', 'CategoryController');
Route::resource('invoices', 'InvoiceController');
Route::resource('proforms', 'ProformController');
});
Duplicate is for it.
In your code you have
// all() gets you the collection of the Invoice Model instances of all the entries of invoice in the database.
$invoice = Invoice::all();
$duplicated = $invoice->create([..
Where
$invoice is a collection of Invoice Model instances. You can't apply create method on a collection.
You need to create by using the Model that you have for Invoice.
So change the above creation code to
$duplicated = Invoice::create([..
I am trying to test my website with dusk, but in many tests i wrote, it is getting failed.
I've used laravel boilerplate 6.0 and dusk for testing.
Below are the code and few test cases and error/failure details.
Login.blade.php
#extends('frontend.layouts.app')
#section('title', app_name() . ' | ' . __('labels.frontend.auth.login_box_title'))
#section('content')
<div class="row justify-content-center align-items-center">
<div class="col col-sm-8 align-self-center">
<div class="card">
<div class="card-header">
<strong>
#lang('labels.frontend.auth.login_box_title')
</strong>
</div><!--card-header-->
<div class="card-body">
{{ html()->form('POST', route('frontend.auth.login.post'))->open() }}
<div class="row">
<div class="col">
<div class="form-group">
{{ html()->label(__('validation.attributes.frontend.email'))->for('email') }}
{{ html()->email('email')
->class('form-control')
->placeholder(__('validation.attributes.frontend.email'))
->attribute('maxlength', 191)
->required() }}
</div><!--form-group-->
</div><!--col-->
</div><!--row-->
<div class="row">
<div class="col">
<div class="form-group">
{{ html()->label(__('validation.attributes.frontend.password'))->for('password') }}
{{ html()->password('password')
->class('form-control')
->placeholder(__('validation.attributes.frontend.password'))
->required() }}
</div><!--form-group-->
</div><!--col-->
</div><!--row-->
<div class="row">
<div class="col">
<div class="form-group">
<div class="checkbox">
{{ html()->label(html()->checkbox('remember', true, 1) . ' ' . __('labels.frontend.auth.remember_me'))->for('remember') }}
</div>
</div><!--form-group-->
</div><!--col-->
</div><!--row-->
<div class="row">
<div class="col">
<div class="form-group clearfix">
{{ form_submit(__('labels.frontend.auth.login_button')) }}
</div><!--form-group-->
</div><!--col-->
</div><!--row-->
#if(config('access.captcha.login'))
<div class="row">
<div class="col">
#captcha
{{ html()->hidden('captcha_status', 'true') }}
</div><!--col-->
</div><!--row-->
#endif
<div class="row">
<div class="col">
<div class="form-group text-right">
#lang('labels.frontend.passwords.forgot_password')
</div><!--form-group-->
</div><!--col-->
</div><!--row-->
{{ html()->form()->close() }}
<div class="row">
<div class="col">
<div class="text-center">
#include('frontend.auth.includes.socialite')
</div>
</div><!--col-->
</div><!--row-->
</div><!--card body-->
</div><!--card-->
</div><!-- col-md-8 -->
</div><!-- row -->
#endsection
#push('after-scripts')
#if(config('access.captcha.login'))
#captchaScripts
#endif
#endpush
UserLoginTest.php
<?php
namespace Tests\Browser;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use App\Events\Frontend\Auth\UserLoggedIn;
use App\Events\Frontend\Auth\UserLoggedOut;
use App\Models\Auth\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Event;
use Illuminate\Validation\ValidationException;
use Laravel\Dusk\Browser;
use Tests\DuskTestCase;
// use Tests\TestCase;
class UserLoginTest extends DuskTestCase
{
/**
* A Dusk test example.
*
* #return void
*/
use RefreshDatabase;
/** #test */
public function the_login_route_exists()
{
$this->get('/login')->assertStatus(200);
}
/** #test */
public function a_user_can_login_with_email_and_password()
{
$user = factory(User::class)->create([
'email' => 'john#example.com',
'password' => 'secret',
]);
Event::fake();
$this->post('/login', [
'email' => 'john#example.com',
'password' => 'secret',
]);
Event::assertDispatched(UserLoggedIn::class);
$this->assertAuthenticatedAs($user);
}
Error:
There was 1 failure:
Tests\Browser\UserLoginTest::a_user_can_login_with_email_and_password
The expected [App\Events\Frontend\Auth\UserLoggedIn] event was not dispatched.
Failed asserting that false is true.
/home/hrishi/TheNewBegining/PHP/Laravel/WebApp-X/vendor/laravel/framework/src/Illuminate/Support/Testing/Fakes/EventFake.php:62
/home/hrishi/TheNewBegining/PHP/Laravel/WebApp-X/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php:261
/home/hrishi/TheNewBegining/PHP/Laravel/WebApp-X/tests/Browser/UserLoginTest.php:46
I've just started coding, and have little experience.
Help me out.
I want to select a single category of questions that the user can select with options. I have tried doing this with a resource I found online.
The category page:
#foreach($categories as $category)
<section>
<a href="#" class="image">
<img src="{{asset('images/pic09.jpg')}}" alt="" data-position="top center" />
</a>
<div class="content">
<div class="inner">
<header class="major">
<h3>{{$category->name}}</h3>
</header>
<p></p>
<ul class="actions">
<li>Learn more</li>
</ul>
</div>
</div>
</section>
#endforeach
Here is the TestController I'm using, the show controller is might to select questions and options with the category_id at random:
namespace App\Http\Controllers;
use App\Category;
use App\Http\Requests\StoreTestRequest;
use App\Option;
class TestsController extends Controller
{
public function show($id)
{
$categories = Category::find($id)->with(
['categoryQuestions' => function ($query) {
$query->inRandomOrder()
->with(
['questionOptions' => function ($query) {
$query->inRandomOrder();
}]
);
}]
)
->whereHas('categoryQuestions')
->get();
return view('client.test', compact('categories'));
}
public function store(StoreTestRequest $request)
{
$options = Option::find(array_values($request->input('questions')));
$result = auth()->user()->userResults()->create(
[
'total_points' => $options->sum('points')
]
);
$questions = $options->mapWithKeys(
function ($option) {
return [$option->question_id => [
'option_id' => $option->id,
'points' => $option->points
]
];
}
)->toArray();
$result->questions()->sync($questions);
return redirect()->route('client.results.show', $result->id);
}
}
web.php
// User
Route::group(['as' => 'client.', 'middleware' => ['auth']], function () {
Route::get('home', 'HomeController#redirect');
Route::get('dashboard', 'HomeController#index')->name('home');
Route::resource('/test', 'TestsController');
Route::get('results/{result_id}', 'ResultsController#show')->name('results.show');
Route::get('send/{result_id}', 'ResultsController#send')->name('results.send');
});
This is the Blade file from the resource I'm using:
#extends('layouts.home')
#section('content')
<div class="container">
<div class="row justify-content-center">
<div class="col-md-8">
<div class="card">
<div class="card-header">Test</div>
<div class="card-body">
#if(session('status'))
<div class="row">
<div class="col-12">
<div class="alert alert-success" role="alert">
{{ session('status') }}
</div>
</div>
</div>
#endif
<form method="POST" action="{{ route('client.test.store') }}">
#csrf
#foreach($categories as $category)
<div class="card mb-3">
<div class="card-header">{{ $category->name }}</div>
<div class="card-body">
#foreach($category->categoryQuestions as $question)
<div class="card #if(!$loop->last)mb-3 #endif">
<div class="card-header">{{ $question->question_text }}</div>
<div class="card-body">
<input type="hidden" name="questions[{{ $question->id }}]" value="">
#foreach($question->questionOptions as $option)
<div class="form-check">
<input class="form-check-input" type="radio" name="questions[{{ $question->id }}]" id="option-{{ $option->id }}" value="{{ $option->id }}"#if(old("questions.$question->id") == $option->id) checked #endif>
<label class="form-check-label" for="option-{{ $option->id }}">
{{ $option->option_text }}
</label>
</div>
#endforeach
#if($errors->has("questions.$question->id"))
<span style="margin-top: .25rem; font-size: 80%; color: #e3342f;" role="alert">
<strong>{{ $errors->first("questions.$question->id") }}</strong>
</span>
#endif
</div>
</div>
#endforeach
</div>
</div>
#endforeach
<div class="form-group row mb-0">
<div class="col-md-6">
<button type="submit" class="btn btn-primary">
Submit
</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
#endsection
How can the Testcontroller be made to select questions and answer from a single category and save the result from the user's answers?
public function index()
{
$questions = Category::select('categories.name', 'question_result.points')
->join('questions', 'categories.id', '=', 'questions.category_id')
->join('question_result', 'questions.id', '=', 'question_result.question_id')
->join('results', 'question_result.result_id', '=', 'results.id')
->where('results.user_id', auth()->id())
->get();
return view('client.home', compact('questions'));
}
I had developed a system that use maddhatter/laravel-fullcalendar.It works and i had no problem to display the calendar with the events.However, there is the problem that the calendar show all events include from different users.Can someone help me to solve this?
Controller
//show the events in the calendar
$events = Schedule::get();
$events->user()->id;
$event_list = [];
foreach ($events as $key => $event) {
$event_list[] = Calendar::event(
$event->event_name,
false,
new \DateTime($event->start_date),
new \DateTime($event->end_date),
null,
// Add color and link on event
[
'color' => '#05B06C',
//'url' => 'http://full-calendar.io',
]);
}
//Display Fullcalendar
$calendar_details = Calendar::addEvents($event_list)
->setOptions([ //set fullcalendar options
'firstDay'=> 1,
'editable'=> true,
'navLinks'=> true,
'selectable' => true,
'durationeditable' => true,
]);
return view('front.teacher.schedule.index', compact('calendar_details','events') );
}
Model
namespace App\Model;
use Illuminate\Database\Eloquent\Model;
class Schedule extends Model
{
protected $fillable=[
'event_name','start_date','end_date'
];
}
View
{!! Form::open(array('route' =>'schedule:addEvents','method'=>'POST','files'=>'true'))!!}
<div class ="row">
<div class="col-xs-12 col-sm-12 col-md-12">
#if(Session::has('success'))
<div class="alert alert-success">{{Session::get('success')}}</div>
#elseif (Session::has('warning'))
<div class="alert alert-danger">{{Session::get('warning')}}</div>
#endif
</div>
<div class="col-xs-4 col-sm-4 col-md-4">
<div class="form-group">
{!! Form::label('event_name','Name:') !!}
<div class="">
{!! Form::text('event_name',null,['class'=>'form-control'])!!}
{!! $errors->first('event_name','<p class="alert alert-danger">:message</p>') !!}
</div>
</div>
</div>
<div class="col-xs-3 col-sm-3 col-sm-3">
<div class="form-group">
{!! Form::label('start_date','Start Date:')!!}
<div class="">
{!! Form::input('datetime-local','start_date',\Carbon\Carbon::now(),['class' => 'form-control']) !!}
{!! $errors->first('start_date', '<p class="alert alert-danger">:message</p>') !!}
</div>
</div>
</div>
<div class="col-xs-3 col-sm-3 col-md-3">
<div class="form-group">
{!!Form::label('end_date','End Date:')!!}
<div class="">
{!! Form::input('datetime-local','end_date',null, ['class' => 'form-control']) !!}
{!! $errors->first('end_date', '<p class="alert alert-danger">:message</p>') !!}
</div>
</div>
</div>
<div class="col-xs-1 col-sm-1 cold-md-1 text-center"> <br/>
{!! Form::submit('Add Event',['class'=>'btn btn-primary']) !!}
</div>
</div>
{!!Form::close() !!}
</div>
</div>
<div class="panel panel-primary">
<div class="panel-heading">My Event Details</div>
<div class="panel-body">
{!! $calendar_details->calendar() !!}
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
#endsection
#section('script')
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.9.0/moment.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/2.2.7/fullcalendar.min.js"></script>
{!! $calendar_details->script() !!}
Schedule Table
Table