Posts

Showing posts with the label laravel

Laravel nested foreach by 2 different Models

Laravel nested foreach by 2 different Models I tried this. problem is, How to foreach data from different Models? Trying to get property of non-object (View: C:wamp64wwwzainsurgaltresourcesviewschoicesindex.blade.php) Controller $duplicates = Question::selectRaw("count('id') as total, topic_id")->with('topic', 'topic.choices')->groupBy('topic_id')->get(); $choices = Choice::where('user_id',Auth::id())->pluck('question_number')->toArray(); return view('choices.index',compact('duplicates','choices')); View @foreach ($duplicates as $duplicate) <tr> <td style="text-align: center;">{{ $duplicate->topic->id }}</td> <td style="text-align: center;">{{ $duplicate->topic->title }}</td> <td style="text-align: center;">{{ $duplicate->total }}</td> <td style=...

Merging Eloquent result set

Merging Eloquent result set I have two eloquent outputs allowance Amount A 100 B 80 C 120 D 150 AND Deductions Amount X 50 Y 60 Z 70 and json appears as $allowance = [{"allname":"A","allamount":"100"},{"allname":"B","allamount":"80"},{"allname":"C","allamount":"120"},{"allname":"D","allamount":"150"}] $Deductions = [{"dedname":"X","dedamount":"50"},{"dedname":"Y","dedamount":"60"},{"dedname":"Z","dedamount":"70"}]. I want new json to be like $new = [{"allname":"A","allamount":"100","dedname":"X","dedamount":"50"},{"allname":"B","allamou...

Mail validation in laravel

Mail validation in laravel I am trying to use laravel form validation. My validation code is: $this->validate(request(), [ 'name' => 'required|alpha_num|max:255', 'email' => 'required|email|max:255|unique:users', 'register_no' => 'required|regex:/(1)[0-9]{3}-[0-9]{3}-[0-9]{3}/', 'password' => 'required|min:6' ]); name takes everything whereas I want only letters & hyphen(-). email takes gt@hj.fhdfygt@hj.fhdfy whereas I want like something@anything.com . register_no says pattern doesn't match I wrote to return like 111-111-001 . name email gt@hj.fhdfygt@hj.fhdfy something@anything.com register_no 111-111-001 There already is an email validator in Laravel – kerbholz Jul 2 at 10:10 2 Answers ...

Laravel: Component HttpKernel Exception MethodNotAllowedHttpException No message

Laravel: Component HttpKernel Exception MethodNotAllowedHttpException No message I'm a newbie to this laravel. i've followed a tutorial and i've checked that i wasn't do anything wrong, and then this error comes up. in this code i tried to Read data from table Inputs and create a page to Insert Data into the database in Inputs table. TicketController: public function index(){ $inputs = Inputs::all(); return view('index', [ 'inputs' => $inputs ]); } public function create(){ return view('create'); } public function store(Request $request) { $inputs = new Inputs(); $inputs->inputName = $request->inputName; $inputs->inputAddress = $request->inputAddress; $inputs->inputBDO = Carbon::parse($request->inputBDO); $inputs->inputEmail = $request->inputEmail; $inputs->inputPhone = $request->inputPhone; $inputs->inputJob = $request->inputJob; $inputs->save()...

rename column in laravel using migration

rename column in laravel using migration I use laravel 5.6 I want change author_ID to user_id author_ID user_id I have columns as mentioned bellow: class CreatePostsTable extends Migration{ public function up() { Schema::create('posts', function (Blueprint $table) { $table->increments('id'); $table->bigInteger('author_ID'); $table->bigInteger('category_ID')->nullable(); $table->longText('post_content'); $table->text('post_title'); $table->string('post_slug', 200); $table->string('post_type', 20); $table->timestamps(); }); } public function down() { Schema::dropIfExists('posts'); } } I use the below link to change my column name : How can I rename column in laravel using migration? then create blow migration : php artisan make:migration rename_aut...

How to host Laravel application in a sufolder along with normal php application?

How to host Laravel application in a sufolder along with normal php application? I have a laravel application and a normal application. I want the normal application to run when user opens example.com/ but when the user opens example.com/laravel_application/ I want the laravel application to run. How can I achieve this. I tried various methods like creating symlinks but I seem to be always redirected to root directory ( example.com/ ) e.g. when I open example.com/laravel_application/login I am open to using apache or nginx. example.com/ example.com/laravel_application/ example.com/ example.com/laravel_application/login 3 Answers 3 It's easier to add a subdomain for Laravel app. Otherwise, you will have to create Laravel routes based on the example.com/laravel_app path. There are two solutions: Create .htaccess file on sub-folder where you put your laravel application. and add the code in .htac...

Laravel hide or remove some database column data from result

Laravel hide or remove some database column data from result in Laravel API i have some method which they are return some fields which i don't want to have in result, for example: API id - email - user_id and they are optional and i can't set this fields into self models, now i'm using this class as ManageResource to hode/remove fields/columns from result like this code: ManageResource hode/remove $user = User::whereApiToken($request->api_token)->first(); $result = ManageResource::make($user)->hide(['id','email']); after using this code that implemented by below class i get only id and email on array keys, but i want to hide them id email ManageResource class: ManageResource namespace AppHttpResources; use IlluminateHttpResourcesJsonResource; class ManageResource extends Resource { /** * @var array */ protected $withoutFields = ; /** * Transform the resource into an array. * * @param IlluminateHttpRequ...

redirect after login and logout

redirect after login and logout I don't how how chang path to redirect my website after login and logout. In first example I found that I must change RedirectIfAuthenticated . But If I have RedirectIfAuthenticated public function handle($request, Closure $next, $guard = null) { if (Auth::guard($guard)->check()) { return redirect()->route('myroute'); } return $next($request); } which doesn't redirect me when I want it to. And where can I change the redirect place after logout? post your controller please. – Adnan Mumtaz Jul 2 at 6:40 Which controller? – MrBelongsTo Jul 2 at 7:17 Login controller – Adnan Mumt...

Export to excel using Laravel Excel 3.0

Export to excel using Laravel Excel 3.0 How to export to excel with Maatwebsite/Laravel-Excel version 3.0 within the image? Maatwebsite/Laravel-Excel I do the export with Exports Class, I need to export with the image, this is the code all I got. https://paste.laravel.io/34e11e43-73c4-42c6-adcc-0206946a8fc8 By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Laravel - saving many rows in one request, possible?

Laravel - saving many rows in one request, possible? I have the following blade: <form method="post" action="{{ route('update-document') }}"> {{csrf_field()}} @foreach($customerDocuments as $document) {!! Form::select('documents',['approved'=>'Approved', 'rejected'=>'Rejected', 'uploaded'=>'Uploaded'], $document->status, ['class' => 'form-control']) !!} @endforeach {!! Form::submit('Save', ['class=', '"btn btn-primary"']); !!} </form> I have about 4 rows where each of row has a select field. I want my update method to save all rows at once. The issue is that Laravel's $request by default knows how to update one row, not many. $request Is there a way to pass all data from all rows into my $request object? $request 1 Answer 1 ...

How to implement the api of the following pushbot link in php

How to implement the api of the following pushbot link in php How to implement the api of the following pushbot link in php https://developer.pushbots.com/api/v2/#/subscriptions/getSub I want to know how to implement this 2/subscription/{DEVICE_ID} api in php By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Vue Router in laravel

Vue Router in laravel I am building laravel-vue website. It have member page which contain register and login components . I want when type "member#/login" then router-view will render login component. My code in app.js : laravel-vue router-view app.js import login from './components/auth/login.vue'; import register from './components/auth/register.vue'; const routes=[ { path:'/register', name:'register', component: register }, { path:'/login', name:'login', component:login } ]; const router=new VueRouter({ routes, mode: 'history', }); const app = new Vue({ el: '#app', router }); I feel it quite confusing. If my current page is home page, it may be occur bug. Someone have good ideal for this situations. Or i keep my code and use window.location for define the page, like this: window.location import login from './components/auth...

Laravel 5.6 Apply Middleware for controller certain methods

Laravel 5.6 Apply Middleware for controller certain methods Laravel 5.6 Apply Middleware for controller certain methods https://laravel.com/docs/5.6/controllers#controller-middleware without write a new class class UserController extends Controller { public function __construct() { // how can apply this middleware for certain methods eg. store, update ? $this->middleware(function ($request, $next) { // i need modify the $request->input('name') // before goes to method store, update // replace any space+ to a single space $request->merge(['name' => preg_replace('/s+/', ' ', $request->input('name'))]); return $next($request); }); } public function store(Request $request) { dd($request->all()); } public function update(Request $request) { dd($request->all()); } } Edited, this is not documented i...

Undefined variable: statuses (View: /Users/domlanza/code/kermode/resources/views/timeline/index.blade.php)

Undefined variable: statuses (View: /Users/domlanza/code/kermode/resources/views/timeline/index.blade.php) I am getting this message and going a little crazy. Here is my code please just try to point me in the right direction it would be greatly appreciated. timeline.index.blade.php @extends('layouts.app') @section('content') <div class="row"> <div class="col-lg-6"> <form role="form" action="{{ route('status.post') }}" method="post"> <div class="form-group {{ $errors->has('status') ? ' has-error' : ''}}"> <textarea placeholder="What's up {{Auth::user()->getFirstNameOrUsername() }} ?" name="status" class="form-control" rows="2"></textarea> @if ($errors->has('status')) <span class="help-b...

Trouble getting $id from session in laravel

Trouble getting $id from session in laravel I am trying to pass on the value $id through my href to the next page Route: Route::get('/offer-me/{id}', 'OffersController@create')->name('project.detailed'); From View: <a href="{{ route('project.detailed', [$product->id]) }}"><button class="btn btn-success">View</button></p></a> When I go to localhost/projectp0/public/offer-me/2 .... There is no $id value? {"_token":"dSxgM8wTlpNxhDKsqj713KMy656bg8XAU5Q2sqe4","_previous":{"url":"http://localhost/projectp0/public/auction"},"_flash":{"old":,"new":},"login_web_59ba36addc2b2f9401580f014c7f58ea4e30989d":1} To get that view i Run: $data = session()->all(); return($data) What is your use case? That could be helpful to get you a proper solution/alternative. – HCK ...

laravel 5 : how to validate multi dimensional checkbox

laravel 5 : how to validate multi dimensional checkbox Hello i have the following in my view <table class="table"> <tbody> @foreach($products as $indexKey => $product) <tr> <td> <input type="checkbox name="order_products[{{$indexKey}}][id]" value="{{$product->id}}"/> </td> <td> <input type="text" name="order_products[{{$indexKey}}][quantity]" value=""/> </td> </tr> @endforeach </tbody> </table> and in my controller $this->validate($request,[ 'order_products'=>'required' ]) how can I validate that if one checkbox is checked, make sure the 'quantity' is not empty? i checked so many websites and nothing comes close to my answer, they are all using just one dimensional array. thank you! ...