Laravel8 - View loaded by @include in loop always keeps a value of the first loop
When I do things like this:
<loader.blade.php>
@foreach($items as $item)
@include('loaded', ['item' => $item])
@endforeach
<loaded.blade.php>
<div>
{{ $item->name }}
</div>
$item
in loaded.blade.php
always has the same value, meaning the value of the first $item
in loop.
Is this normal? If so, how can I avoid it. If that is not normal, what might be causing this problem?
1 answer
-
answered 2021-04-08 04:34
BABAK ASHRAFI
You can use
@each()
method for this porpuse as described here in laravel doc@each('loaded', $items, 'item')
Where
loaded.blade.php
is as follows<div> {{ $item->name }} </div>
See also questions close to this topic
-
WooCommerce Dynamic Product Category Slug based on Country Code
Is there a way to write a custom code to create different versions of the product category URL, based on the user visited country, handling what is the country code is an easy part however I want to have a dynamic URL based on detected country code.
for example
https://website.com/uk/category1
https://website.com/us/category1
https://website.com/fr/category1
this will be for the same product category, all I need is to have a dynamic product category prefix based on this dynamic variable from the visitor session (country code)
-
bref.sh php container for AWS Lambda with Neos CMS
I'm struggling to get Neos (a php based cms) to run in a docker container for AWS Lambda. I guess I have somewhere a misunderstanding and hope anyone can help.
What I did so far:
- I adjusted Neos so that all cache files will be written to the tmp folder
- I added the bref and extra-php-extensions package to composer.json
- I created a docker file, quite simple as shown by Mattheu Naploli's blog article: https://mnapoli.fr/aws-lambda-php-docker-containers/
- I have created a cloudformation template to use
sam local start-api
Dockerfile:
FROM bref/php-74-fpm COPY . /var/task # Start Bref's runtime client CMD _HANDLER=Web/index.php /opt/bootstrap
template.yml
AWSTemplateFormatVersion: '2010-09-09' Transform: AWS::Serverless-2016-10-31 Description: > neos-demo-lambda Sample SAM Template for neos-demo-lambda # More info about Globals: https://github.com/awslabs/serverless-application-model/blob/master/docs/globals.rst Globals: Function: Timeout: 3 Resources: Neos: Type: AWS::Serverless::Function Properties: Description: Show neos demo PackageType: Image ImageUri: neos7.demo.lambda.php74:latest #Handler: "Web/index.php /opt/bootstrap" #Handler: "Web/index.php" MemorySize: 1024 Timeout: 360 Environment: Variables: FLOW_CONTEXT: 'Production' FLOW_PATH_TEMPORARY_BASE: '/tmp/neos' FLOW_PATH_DATA_BASE: '/tmp/Data' BREF_AUTOLOAD_PATH: '/var/task/Packages/Libraries/autoload.php' AWS_S3_BUCKET_STORAGE: 'neos-lambda-demo-private' AWS_S3_BUCKET_TARGET: 'neos-lambda-demo-public' AWS_CLOUDFRONT_BASE_URI: '' AWS_REDIS_HOST: '' Events: htmlHttpApi: Type: HttpApi TimeoutInMillis: 28000 Metadata: DockerTag: neos7.lambda.demo DockerContext: ./Web/index.php Dockerfile: Dockerfile
Response of
sam local start-api
:entrypoint requires the handler name to be the first argument time="2021-04-14T22:11:48.093" level=error msg="Init failed" InvokeID= error="Runtime exited with error: exit status 142" time="2021-04-14T22:11:48.093" level=error msg="INIT DONE failed: Runtime.ExitError" Invalid lambda response received: Lambda response must be valid json 2021-04-15 00:11:48 127.0.0.1 - - [15/Apr/2021 00:11:48] "GET / HTTP/1.1" 502 -
What I don't understand, I'd expect that there is always a valid json returned, even though the php delivers a 5xx error. I'm lost ... even though this wouldn't be the case, how can I debug the issue?
In the end, I have to create my own docker image as Neos is too big to use the bref layers and I need quite some php extensions. If I could understand the current issue, I can work through this and provide a working container for everyone.
I have a few more questions, in this scenario, were I have a web application and use a container, do I have to install the bref packages with composer? That wasn't clear in the blog post. Also do I have to set the Handler in serverless/sam and if so, which would be the correct string, given that
Web/index.php
is the path in Neos?In general, Neos would work awesome in AWS. My setup would be:
- CloudFront with behaviors for static files from S3 and everything else to lambda
- Redis to store cache files from Neos
- ElasticSearch for website search and improved performance on huge sites
As soon as this is working, I'll publish all information for free for the Neos community to get this working.
Hope someone can help...
Thank you!
-
laravel 7 nothing happens when i click sign up button it seems like event is not triggering
hello and sorry for my bad English , can any one help me ? when i try to sign up nothing happens . i use laravel 7. every time I click the sign up button, nothing happens and also no errors are showing.
UserController.php
namespace App\Http\Controllers\Web\User; use Reminder; use Exception; use Modules\User\Http\Controllers\AuthController; class UserController extends AuthController { public $routes = [ 'home' => 'web.home.index', 'forgot_password' => 'frontend.forgot.password', 'reset_password' => 'web.user.reset-password', ]; public function getLogin() { $return_url = ''; if ( request()->has('return-url') ) $return_url .= request()->input('return-url'); $data = [ 'authenticate_url' => route('web.user.authenticate', ['return-url' => strip_tags(trim($return_url))]) ]; return view('web.user.login', $data); } /** * getNewAccount * * @return view */ public function getNewAccount() { return view('web.user.new-account')->with(['url' => route('web.user.post-new-account')]); } /** * Logout current user. * * @return void */ public function getForgotPassword() { return view('web.user.forgot-password')->with(['url' => route('web.user.post-forgot-password')]); } /** * * getResetPassword() * * @return template * @access public **/ public function getResetPassword($userHashId,$reminderCode) { try { $hashId = hasher($userHashId, true); if ( !$hashId ) throw new Exception('Wrong user hash key, please check the url carefully.'); $user = $this->auth->findById($hashId); $isReminderCodeExist = Reminder::exists($user); if(!$isReminderCodeExist) throw new Exception("Reset code is not exists, please retry."); return view('web.user.reset-password')->with(['url' => route('web.user.post-reset-password'), 'code' => $reminderCode, 'hash_code' => $userHashId ]); } catch (Exception $e) { return redirect()->back()->withInput()->withErrors($e->getMessage()); } } }
new-account.blade.php
@extends( "layouts.master-login") @section('content') <div class="row no-gutters justify-content-center "> <div class="hero-static col-sm-8 col-md-8 col-xl-8 d-flex align-items-center px-sm-0"> <div class="col-md-12 col-xl-10" style="margin: 0 auto;"> <div class="row no-gutters"> <div class="col-md-6 order-md-1 bg-white"> <div class="block-content block-content-full px-lg-5 py-md-5 py-lg-6"> <!-- Header --> <div class="mb-2 text-center"> <p> @include('common.logo')</p> <p class="text-uppercase font-w700 font-size-sm text-muted"> {{ __('dcm.new_account')}} </p> </div> <!-- END Header --> <!-- Sign In Form --> <form action="{{ $url }}" method="POST"> @if(session('error.message') ) <div class="form-group"> <span class="text-danger">{{ session('error.message') }}</span> </div> @endif @csrf <div class="form-group"> <input type="text" class="form-control form-control-alt {{ $errors->has('username') ? ' is-invalid' : '' }}" id="username-username" name="username" placeholder="{{ __('dcm.username_placeholder')}}"> {!! $errors->first('username', '<span class="text-danger">:message</span>') !!} </div> <div class="form-group"> <input type="text" class="form-control form-control-alt {{ $errors->has('email') ? ' is-invalid' : '' }}" id="email-email" name="email" placeholder="{{ __('dcm.email_placeholder')}}"> {!! $errors->first('email', '<span class="text-danger">:message</span>') !!} </div> <div class="form-group"> <input type="text" class="form-control form-control-alt {{ $errors->has('first_name') ? ' is-invalid' : '' }}" id="first_name-first_name" name="first_name" placeholder="{{ __('dcm.firstname_placeholder')}}"> {!! $errors->first('first_name', '<span class="text-danger">:message</span>') !!} </div> <div class="form-group"> <input type="text" class="form-control form-control-alt {{ $errors->has('last_name') ? ' is-invalid' : '' }}" id="last_name-last_name" name="last_name" placeholder="{{ __('dcm.lastname_placeholder')}}"> {!! $errors->first('last_name', '<span class="text-danger">:message</span>') !!} </div> <div class="form-group"> <input type="password" class="form-control form-control-alt {{ $errors->has('password') ? ' is-invalid' : '' }}" id="password" name="password" placeholder="{{ __('dcm.password_placeholder')}}"> {!! $errors->first('password', '<span class="text-danger">:message</span>') !!} </div> <div class="form-group"> <button type="submit" class="btn btn-block btn-hero-primary"> <i class="fas fa-plus mr-1"></i> {{ __('dcm.sign_up')}} </button> </div> <hr/> <div class="form-group"> <p class="mt-3 mb-0 d-lg-flex justify-content-lg-between"> <a class="btn btn-secondary btn-block d-block d-lg-inline-block mb-1" href="{{ route('web.user.index') }}" title="{{ __('dcm.sign_in')}}"> <i class="fa fa-fw fa-sign-in-alt mr-1"></i> {{ __('dcm.sign_in')}} </a> </p> </div> </form> <!-- END Sign In Form -->
routes/web/user.php
<?php // using this pattern to used php artisan route:cache, // instead of using router closure/grouping. $userRouteNameSpace = 'Web\User'; $middlewareName = 'dcm.logged.in'; // UserController $userController = "{$userRouteNameSpace}\UserController"; // authenticate user Route::get('user/login', "{$userController}@getLogin")->name('web.user.index'); Route::post('user/authenticate', "{$userController}@postAuthenticate") ->name('web.user.authenticate'); // logout user Route::get('user/logout', "{$userController}@logout") ->name('web.user.logout'); // forgot password Route::get('user/forgot-password', "{$userController}@getForgotPassword") ->name('web.user.forgot-password'); Route::post('user/forgot-password', "{$userController}@postForgotPassword") ->name('web.user.post-forgot-password'); // reset password Route::get('user/reset-password/{hashId}/{resetcode}', "{$userController}@getResetPassword") ->name('web.user.reset-password'); Route::post('user/reset-password', "{$userController}@postResetPassword") ->name('web.user.post-reset-password'); // create new user account Route::get('user/new-account', "{$userController}@getNewAccount") ->name('web.user.new-account'); Route::post('user/new-account', "{$userController}@postNewAccount") ->name('web.user.post-new-account'); // ProfileController $profileController = "{$userRouteNameSpace}\ProfileController"; Route::get('user/profile', "{$profileController}@getProfile") ->name('web.user.profile') ->middleware($middlewareName); Route::post('user/update-profile', "{$profileController}@postUpdateProfile") ->name('web.user.update.profile') ->middleware($middlewareName); // update user avatar Route::post('user/update-avatar/{hashId}', "{$profileController}@postUpdateAvatar") ->name('web.user.update.avatar') ->middleware($middlewareName); // Verify User Route::get('/verify','Auth\RegisterController@verifyUser')->name('verify.user');
When I click on sign up, nothing happens, it seems like event is not triggering
-
Get join values Laravel
According documentation about joins:
https://laravel.com/docs/8.x/queries#joins
As example:
$users = DB::table('users') ->join('contacts', 'users.id', '=', 'contacts.user_id') ->join('orders', 'users.id', '=', 'orders.user_id') ->select('users.*', 'contacts.phone', 'orders.price') ->get();
OK, I have my values into $users. If I do, with blade:
{{ $users }}
I can see this result, in JSON format. But, How can I get each single value, using Blade? (Ex: contacts.phone, or orders.price, in this example)
Thanks on advance
-
Why Heroku does not accept my debit card?
When I enter my debit card details on Heroku, a message appears to me that says
Unable to verify your card. Please try later or contact your financial institution for help.
Knowing that I'm from Egypt. So, What should I do in this case, please?