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([..
Related
How to show label in a loop.For example label 1, label 2 and so on continuous till the end of the loop.
Here is my code i want to show Experience 1 and Experience 2 and so on through out the loop
till loop ends.
#foreach($employee->experiences as $experince)
<div class="card-header">
<label for="">Experience</label>
</div>
<div class="card-body">
<div class="row">
<div class="col-md-6">
<div class="form-group row">
<div class="col-md-6"><b>Company:</b></div>
<div class="col-md-6">{{ ucfirst($experince->company) }}</div>
</div>
</div>
<div class="col-md-6">
<div class="form-group row">
<div class="col-md-6"><b>Degree :</b></div>
<div class="col-md-6">{{ ucfirst($employee->degree) }}</div>
</div>
</div>
</div>
</div>
#endforeach
In blade template there is a $loop variable:
$loop->index
will print the current index, starting from 0
$loop->iteration
will instead start from 1
The variable is available inside a #foreach:
#foreach($employee->experiences as $experince)
{{ $loop->iteration }}
#endforeach
Try this $loop->iteration ref link https://laravel.com/docs/8.x/blade#the-loop-variable
#foreach($employee->experiences $experince)
<div class="card-header">
<label for="">Experience {{ $loop->iteration }}</label>
</div>
<div class="card-body">
<div class="row">
<div class="col-md-6">
<div class="form-group row">
<div class="col-md-6"><b>Company:</b></div>
<div class="col-md-6">{{ ucfirst($experince->company) }}</div>
</div>
</div>
<div class="col-md-6">
<div class="form-group row">
<div class="col-md-6"><b>Degree :</b></div>
<div class="col-md-6">{{ ucfirst($employee->degree) }}</div>
</div>
</div>
</div>
</div>
#endforeach
Create it variable as iteration and increment it each iterations
#php
$it = 1;
#endphp
#foreach($employee->experiences as $experince)
<div class="card-header">
<label for="">Experience</label>
</div>
<div class="card-body">
<div class="row">
<div class="col-md-6">
<div class="form-group row">
<div class="col-md-6"><b>Label:{{ $it }}</b></div>
<div class="col-md-6"><b>Company:</b></div>
<div class="col-md-6">{{ ucfirst($experince->company) }}</div>
</div>
</div>
<div class="col-md-6">
<div class="form-group row">
<div class="col-md-6"><b>Degree :</b></div>
<div class="col-md-6">{{ ucfirst($employee->degree) }}</div>
</div>
</div>
</div>
</div>
#php
$it += 1;
#endphp
#endforeach
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 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
I have Laravel form with many multiple select elements which has many data. for ex:
Hotel select (600 option)
Restaurants select (800 option)
SPA select (200 option)
Attractions select (150 option)
Outlets select (500 option)
If I select all options in all inputs, in the controller when checking the
request the (Outlets) item has only 200 option
how to fix this? how to got all data sent from this form?
is there any form data size in Laravel?
This my form code:
<div class="row">
<div class="panel panel-white">
<div class="panel-body">
<div class="col-md-12 col-sm-12">
<div class="form-group">
{{ Form::label('hotels', __('membership::main.hotels')) }}
{{ Form::select('hotels', $hotels, null, array('multiple'=>'multiple','name'=>'hotels[]', 'class' => 'multiselect form-control')) }}
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="panel panel-white">
<div class="panel-body">
<div class="col-md-12 col-sm-12">
<div class="form-group">
{{ Form::label('outlets', __('membership::main.outlets')) }}
{{ Form::select('outlets', $outlets, null, array('multiple'=>'multiple','name'=>'outlets[]', 'class' => 'multiselect form-control')) }}
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="panel panel-white">
<div class="panel-body">
<div class="col-md-12 col-sm-12">
<div class="form-group">
{{ Form::label('airports', 'Airport & Lounges') }}
{{ Form::select('airports', $airports, null, array('multiple'=>'multiple','name'=>'airports[]', 'class' => 'multiselect form-control')) }}
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="panel panel-white">
<div class="panel-body">
<div class="col-md-12 col-sm-12">
<div class="form-group">
{{ Form::label('beauty', 'Beauty & Fitness') }}
{{ Form::select('beauty', $beauty, null, array('multiple'=>'multiple','name'=>'beauty[]', 'class' => 'multiselect2 form-control')) }}
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="panel panel-white">
<div class="panel-body">
<div class="col-md-12 col-sm-12">
<div class="form-group">
{{ Form::label('attractions', 'Activities & Attractions') }}
{{ Form::select('attractions', $attractions, null, array('multiple'=>'multiple','name'=>'attractions[]', 'class' => 'multiselect2 form-control')) }}
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="panel panel-white">
<div class="panel-body">
<div class="col-md-12 col-sm-12">
<div class="form-group">
{{ Form::label('restaurants', 'Restaurant & Bars') }}
{{ Form::select('restaurants', $restaurants, null, array('multiple'=>'multiple','name'=>'restaurants[]', 'class' => 'multiselect3 form-control')) }}
</div>
</div>
</div>
</div>
</div>
And I am using this library to handle multiselect function
https://github.com/davidstutz/bootstrap-multiselect
in controller I just checking the data like this, and I not all my selection was submitted, its stop on specific limit but I don't know why?
public function store(Request $request)
{
dd($request);
}
Having so much options is not Ideal! However, I propose you look at your controller. Its possible that you paginate your result. Also it could be browser related. Until we see what you have done or what you seeing, we cannot give your an exact answer...only assumptions
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'