please show your edit_product.blade.php file
Parse error
When I try to edit the product from my ecommerce backend. I am getting this error message:
Parse error: syntax error, unexpected '@' (View: C:\xampp\htdocs\eliteshop\resources\views\admin\products\edit_product.blade.php)
Any clue why is that?
Here is the edit button:
admin/products/products.blade.php
<td>
<a href="{{url( '/cpages/products/'. $product->prod_id .'/edit')}}" class="edit">Edit</a>
<form style="display:inline" method="POST" action="{{url( '/cpages/products/'. $product->prod_id )}}">
{{ csrf_field()}}
{{ method_field('DELETE') }}
<input type="submit" class="delete fix-inline-btn" value="Delete" />
</form>
</td>
edit_product.blade.php
@extends('layouts.admin_master')
@section('breadcrumb')
<a href="{{ url('/cpages/')}}" title="Go to Home" class="tip-bottom"><i class="icon-home"></i> Home</a>
<a href="#" class="tip-bottom">Content Mgt</a>
<a href=" {{ url('cpages/products') }}" class="tip-bottom">Products</a>
<a href="#" class="current">Edit Product</a>
@endsection
@section('title')
Edit Product
@endsection
@section('content')
<div class="container-fluid ">
<form action=" {{ url('cpages/products/') }}" method="post">
{{ method_field('PATCH') }}
{{ csrf_field()}}
<div class="form-group row">
<input type="hidden" value="{{ $product->prod_id }}" name="prod_id" />
<div class="col-md-8">
<div>
<label for="prod_name">Product Name:</label>
<input type="text" class="form-control" id="prod_name" name="prod_name" value="{{ $product->prod_name }}" required>
</div>
<div>
<label for="prod_price">Product Price:</label>
<input type="text" class="form-control" id="prod_price" name="prod_price" value="{{ $product->prod_price }}" required>
</div>
<div>
<label for="prod_weight">Product Weight:</label>
<input type="text" class="form-control" id="prod_weight" name="prod_weight" value="{{ $product->prod_weight }}" required>
</div>
<div>
<label for="prod_stock">Product Stock (leave empty if unlimited):</label>
<input type="number" class="form-control" id="prod_stock" name="prod_stock" value="{{ $product->prod_stock }}"
@if($product->prod_stockable != true)
disabled
@endif
/>
<div class="checkbox">
<label><input type="checkbox" id="prod_stockable" value="1" name="prod_stockable"
@if($product->prod_stockable)
checked
@endif
/>Product is stockable</label>
</div>
</div>
<div>
<label for="prod_description">Product Description:</label>
<textarea class="form-control" rows="4" style="width: 600px" id="prod_description" name="prod_description">{{ $product->prod_description }}</textarea>
</div>
<div>
<label for="prod_main_img">Product Main Images [Recommended: 480 x 618 pixels]</label>
<br />
<!-- Product Main Image -->
@if( $product->prod_main_img != null)
<input id="prod_main_img_input" value="{{ $product->prod_main_img }}" type="hidden" name="prod_main_img" />
<p id="prod_main_img_name">{{ $product->productMainImage->img_name }}</p>
<img id="prod_main_img_preview" src="{{ $product->productMainImage->img_thumb_url }}" style="width:250px; height:150px; display:none;"/>
@else
<input id="prod_main_img_input" type="hidden" name="prod_main_img" value="" />
<p id="prod_main_img_name"></p>
<img id="prod_main_img_preview" src="#" style="width:250px; height:150px;"/>
@endif
<br /><br />
<button type="button" id="select_img_button" class="edit edit-subcat" data-toggle="modal" data-target="#productMainModal" >Select Image</button>
<button type="button" id="delete_img_button" @if( $product->prod_main_img != null) style="display:none;" @endif class="delete edit-subcat">Remove Main Picture</button>
</div>
<div>
<label for="prod_gallery_img">Product Galleries</label>
<br />
<p id="prod_input_gallery">
@if($product_gallery != null)
@foreach($product_gallery['prod_index'] as $value)
<input type="hidden" name="prod_gallery[]" value="{{ $value }}" />
@endforeach
@endif
</p>
<p id="prod_gallery_img_preview">
@if($product_gallery != null)
{{ count($product_gallery['prod_index']) }} picture(s) selected
@endif
</p>
<button type="button" id="select_gallery_img_button" class="edit edit-subcat" data-toggle="modal" data-target="#galleryModal" >Select Images</button>
<button type="button" id="delete_gallery_img_button"@if($product_gallery != null) style="display: none;" @endif class="delete edit-subcat">Reset</button>
</div>
<div class="form-group">
<div class="checkbox">
<label><input type="checkbox" name="prod_featured" value="1" @if($product->prod_featured) checked @endif>Featured Product</label>
</div>
</div>
</div>
<div class="col-md-4">
<div>
<label for="prod_cat">Product Categories:</label>
<br />
@php ($i = 0)
@foreach($categories as $category)
<label class="checkbox">
<input type="checkbox" name="prod_cat[]" value="{{ $category->cat_id }}"
@foreach($product->productMetas->toArray() as $metas)
@if($metas['prod_meta_type'] == 1)
@if($metas['value'] == $category->cat_id)
checked
@endif
@endif
@endforeach
><strong> {{$category->cat_name}} </strong></input>
</label>
@foreach($categories[$i]->subCategories as $subcategory)
<label class="checkbox-inline">
└ <input type="checkbox" name="prod_subcat[]" value="{{ $subcategory->subcat_id }}"
@foreach($product->productMetas->toArray() as $metas)
@if($metas['prod_meta_type'] == 2)
@if($metas['value'] == $subcategory->subcat_id)
checked
@endif
@endif
@endforeach
>{{$subcategory->subcat_name}}</input>
</label>
<br />
@endforeach
@php ($i++)
@endforeach
</div>
</div>
<div class="row">
<div class="col-md-12">
<div>
<input type="submit" class="btn btn-success btn-lg pull-right" id="submit" style="margin-right:20px" value="Edit Product" />
</div>
</div>
</div>
</form>
</div>
@include('admin.products.modal.primary_product_image')
@include('admin.products.modal.gallery_product')
@endsection
@section('additional_script')
<script src="{{ URL::asset('js/images/create_product.js') }}"></script>
<script type="text/javascript">
$(document).ready(function() {
localStorage.clear();
@php
if($product_gallery != null) {
$prod_index = json_encode($product_gallery['prod_index']);
$prod_name = json_encode($product_gallery['prod_name']);
$prod_gallery_image = json_encode($product_gallery['prod_gallery_image']);
echo "var prod_index = ". $prod_index .";";
echo "var prod_name = ". $prod_name .";";
echo "var prod_gallery_image = ". $prod_gallery_image .";";
}
@endphp
localStorage.setItem('prod_index', JSON.stringify(prod_index));
localStorage.setItem('prod_name', JSON.stringify(prod_name));
localStorage.setItem('prod_gallery_image', JSON.stringify(prod_gallery_image));
});
</script>
@endsection
remove lines below and try if error fixed something wrong here. you have to find
<div class="col-md-4">
<div>
<label for="prod_cat">Product Categories:</label>
<br />
@php ($i = 0)
@foreach($categories as $category)
<label class="checkbox">
<input type="checkbox" name="prod_cat[]" value="{{ $category->cat_id }}"
@foreach($product->productMetas->toArray() as $metas)
@if($metas['prod_meta_type'] == 1)
@if($metas['value'] == $category->cat_id)
checked
@endif
@endif
@endforeach
><strong> {{$category->cat_name}} </strong></input>
</label>
@foreach($categories[$i]->subCategories as $subcategory)
<label class="checkbox-inline">
└ <input type="checkbox" name="prod_subcat[]" value="{{ $subcategory->subcat_id }}"
@foreach($product->productMetas->toArray() as $metas)
@if($metas['prod_meta_type'] == 2)
@if($metas['value'] == $subcategory->subcat_id)
checked
@endif
@endif
@endforeach
>{{$subcategory->subcat_name}}</input>
</label>
<br />
@endforeach
@php ($i++)
@endforeach
</div>
</div>
look over your included files . there is typo with @
@include('admin.products.modal.primary_product_image')
@include('admin.products.modal.gallery_product')
Do you mean I don't need this "@"?
I only have two include file.
Also line 120 is highlighted in red:
@foreach($categories as $category)
"Parse error: syntax error, unexpected '@'"
Change
@php ($i = 0)
@foreach($categories as $category)
to
@foreach($categories as $i => $category)
and change this
@endforeach
@php ($i++)
@endforeach
to just
@endforeach
@endforeach
The problem is you are not closing your php tags with @endphp, so it errors on the very next thing that starts with @, but you don't need to use a separate counter anyway if you use the index of the arrays in your foreach loops, which start at 0, and increment on each loop like I did here @foreach($categories as $i => $category)
Please or to participate in this conversation.