I have a function that store image to the storage/app/images
$filename = $image->getClientOriginalName();
if ($request->hasFile('image'))
{
$request->file('image')->storeAs('images', $filename);
}
$creator = new Content_form([
'media_id' => $request->get('media_name'),
'content_title' => $request->get('content_title'),
'content_description' => $request->get('content_description'),
'date_occured' =>\Carbon\Carbon::now()->format('Y-m-d'),
'page_number' => $request->get('page_number'),
'image' => $filename,
]);
$creator->save();
Image is stored in the database and in the storage/app/image only failed to retrieve those image here is my blade
#foreach($pendingNews as $number=> $post)
<td style="font-size: 16px; width: 210px"><img class="img-rounded" width="150" height="130" src="{{ asset('storage/app/images/'.$post->image) }}"></td>
#endforeach
Also file system I have
'disks' => [
'local' => [
'driver' => 'local',
'root' => storage_path('app'),
],
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'visibility' => 'public',
],
Remove /app from asset('storage/app/images/'.$post->image)
Related
I created a page where I can upload files to "/storage/app/public/uploads". I have a download button, which works fine on my XAMPP test environment. As I uploaded the project to the server, I still can upload files. They also go to the same directory "/storage/app/public/uploads". But when I want to download them, the download-path is /storage/uploads/ and I get a 404 error. But this is also on my XAMPP.
in my /config/filesystems.php i have
'disks' => [
'local' => [
'driver' => 'local',
'root' => storage_path('app'),
],
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
],
'links' => [
public_path('storage') => storage_path('app/public'),
],
]
I have no clue, what's wrong, because on my XAMPP it's fine. Any idea?
example can you create a new controller for example,
<a hrfe="{{route('downloadfile1')}}">download</a>
public function downloadfile1(){
$file=public_path()."/file1.pdf";
$headers = array(
'Content-Type: application/pdf',
);
return Response::download($file, 'filename.pdf', $headers);
}
Run php artisan storage:link on server to fix it.
I am using Google reCaptcha v3. I am trying to implement it onto my profile page.It's load and shown in my page ,but when I want to verify it ,it does not work ,I am using this package:https://github.com/RyanDaDeng/laravel-google-recaptcha-v3#settings
in this config :
'secret_key' => env('RECAPTCHA_V3_SECRET_KEY', '6LcqC'),
'site_key' => env('RECAPTCHA_V3_SITE_KEY', '6LcqnrO-K-xb'),
in this blade :
<form>
{!! GoogleReCaptchaV3::renderOne('contact_us_id','contact_us') !!}
</form>
in my controller:
public function get_data_edit(Request $request)
{
$request->validate(
[
'phone' => ['required', 'max:11', new phone],
'year' => 'nullable|numeric',
'month' => 'nullable|numeric|max:12',
'day' => 'nullable|numeric|max:31',
'sex' => 'nullable|boolean',
'marital_status' => 'nullable|boolean',
'f_name' => 'required|max:15',
'l_name' => 'required|max:20',
'job' => 'nullable|string',
'email' => 'nullable|email',
'national_code' => 'nullable|min:10|max:10',
'family_role' => 'nullable|string',
'g-recaptcha-response' => [new GoogleReCaptchaV3ValidationRule('contact_us')]
],
[]
);
where is my problem ?
I have this simple code
public function store(Request $request)
{
$this->Validate($request, [
'name' => 'required|min:3|max:20',
'age' => 'required|integer|between:18,99',
'height' => 'required|integer|between:120,230',
'weight' => 'required|integer|between:30,150',
'region' => 'required|integer',
'city' => 'required',
'phone' => 'required|integer'
]);
Person::create([
'name' => $request->name,
'age' => $request->age,
'height' => $request->height,
'weight' => $request->weight,
'city_id' => $request->city,
'region_id' => $request->region,
'phone' => $request->phone,
'user_id' => Auth::user()->id
]);
}
This code stop working but it doesn't show error. I have only white page. This code has worked before. And ne record doesn't create. What happend?
#edit
Now it works but... In phpmyadmin everything is ok. New records are added coccectly but tinker show my only one record which I added manually in phpmyadmin. If I try choose the lastest record added by me:
$latest = Person::where('user_id', Auth::user()->id)->latest()->first();
It show me this single element which I created in phpmyadmin. What's wrong?
Replace store as below:
public function store(Request $request) {
$this->Validate($request->all(), [
'name' => 'required|min:3|max:20',
'age' => 'required|integer|between:18,99',
'height' => 'required|integer|between:120,230',
'weight' => 'required|integer|between:30,150',
'region' => 'required|integer',
'city' => 'required',
'phone' => 'required|integer'
]);
$person= new Person();
$person->username= $request['username'];
$person->age = $request['age'];
$person->height = $request['height'];
$person->weight = $request['weight'];
$person->region = $request['region'];
$person->city = $request['city'];
$person->phone = $request['phone'];
$person->save();
}
in your controller :
public function store(Request $request)
{
$this->validate($request, [
'name' => 'required|min:3|max:20',
'age' => 'required|integer|between:18,99',
'height' => 'required|integer|between:120,230',
'weight' => 'required|integer|between:30,150',
'region' => 'required|integer',
'city' => 'required',
'phone' => 'required|integer'
]);
Person::create([
'name' => $request->name,
'age' => $request->age,
'height' => $request->height,
'weight' => $request->weight,
'city_id' => $request->city,
'region_id' => $request->region,
'phone' => $request->phone,
'user_id' => Auth::user()->id
]);
return redirect()->back()->with('success','Person Created');
}
in your blade view :
#if (count($errors) > 0)
#foreach ($errors->all() as $error)
<p class="alert alert-danger alert-dismissible fade show" role="alert">{{ $error }}
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</p>
#endforeach
#endif
i'm trying without success to add an image inside a Navbar menuItem.
It works fine in the brandLabel
But doesn't work on anoter menu item
(I Want to display the logged user image near his name)
I Tryed several times but doesnt seem to make it work,
Would apreciate your help please...
The Code is this:
<?php $this->beginBody() ?>
<div class="wrap">
<?php
NavBar::begin([
'brandLabel' => Html::img('#themes'.'/siteImages/Logo.jpg', ['alt'=>Yii::$app->name]),
'options' => [
'class' => 'navbar-default navbar-fixed-top',
],
]);
// display Login page to guests of the site
if (Yii::$app->user->isGuest) {
$menuItems[] = ['label' => Yii::t('app', 'Login'), 'url' => ['/site/login'],
'options' => [
'class' => 'navbar-right',
],];
}
else
{
// Show sales content to sales+ users
if ( Yii::$app->user->can('useSalesContent'))
{
$menuItems[] = ['label' => Yii::t('app', 'Sales'),
// 'class' => "pull-left",
'url' => Yii::$app->homeUrl,
'linkOptions' => ['id' => 'sales',
'class' => 'navbar-left',
],
];
// Show Admin content to manager+ users
if (Yii::$app->user->can('useAdminContent'))
{
$menuItems[] = ['label' => Yii::t('app', 'Administration'),
'url' => Yii::$app->homeUrl,
'linkOptions' => ['id' => 'admin'],
'options' => [
'class' => 'navbar-left',
],];
}
// display Logout to logged in users
if (!Yii::$app->user->isGuest) {
$menuItems[] =
[
'label' => Yii::t('app', 'Logout'). ' (' . Yii::$app->user-
>identity->username . ')',
'url' => ['/site/logout'],
'linkOptions' => ['data-method' => 'post']
//****** This is where I want the user image to be shown ****//
];
}
}
// echo navbar with selected items
echo Nav::widget([
'options' => ['class' => 'navbar-nav navbar-right'],
'items' => $menuItems,
]);
NavBar::end();
?>
<div class="container">
<?= Alert::widget() ?>
<?= $content ?>
</div>
endBody() ?>
Provided the user model has an attribute imageUrl it would be accessible through:
Yii::$app->user->identity->imageUrl
This would become something like:
If you would like to add it to the logout button:
$menuItems[] = [ 'encode'=>false, label' => Yii::t('app', 'Logout'). ' (' . Yii::$app->user- >identity->username . ') ' . Html::img(Yii::$app->user- >identity->imageUrl), 'url' => ['/site/logout'], 'linkOptions' => ['data-method' => 'post']];
make sure you include 'encode' => false,
To add it as a separate item (for instance, to give it a different link):
$menuItems[] = [ 'encode' => false, 'label' => Html::image(Yii::$app->user- >identity->imageUrl)];
Edit:
Make sure you include the Html with a use statement in your view, or provide the full namespace declaration with Html class.
I want to pass multidimensional Array to Blade file using Controller method:
return view('msg.simple', [
'message' => 'here is my message',
'links' => [
[
'title' => 'link title 1',
'url' => 'www.example.com'
],
[
'title' => 'link title 2',
'url' => '#2'
]
]
]);
view file (blade):
#foreach($links as $link)
{{$link->title}}
#endforeach
but it shows the following error:
htmlspecialchars() expects parameter 1 to be string, array given
Use this :
$data = [
'message' => 'here is my message',
'links' => [
[
'title' => 'link title 1',
'url' => 'www.example.com'
],
[
'title' => 'link title 2',
'url' => '#2'
]
]
];
return view('msg.simple',compact('data'));
and in view file :
#foreach($data['links'] as $link)
{{$link['title']}}
#endforeach
Try
#foreach($links[0] as $link)
{{$link->title}}
#endforeach