Error in URL when i sharing the article on Twitter - php

when i'm use share from my web to twitter by:
<a href="https://twitter.com/share?
url=http://www.noor-journal.com/{{ $posts->category->slug.'/'.$posts->title }}
&text={{ $posts->author->name }} يكتب: {{ $posts->title }}
&{{ url($posts->category->slug.'/'.$posts->title) }}
&via=NoorJournals"
class="share-btn twitter"
target="_blank">
<i class="fa fa-twitter"></i>
</a>
the tweet send without URL Link because the URL it contains Arabic words and spaces like: this
i'm using PHP in Laravel.
Thank you

Related

Is it possible to remove variable from symfony url?

/category/{id}/{categoryName}
localhost:8000/category/2/tours-and-travels
localhost:8000/category/tours-and-travels //want to have this url.
Is it possible to remove id as shown above url?
Twig
<a class="nav-link text-white" href="{{ path('category_with_id',{'id': category.id, 'categoryName': category.name|slug('-') }) }}">
{{ category.name }}
</a>
I know we can do this with the help of unique slug, but is it possible with id?

Trying to use Laravel policies into components

I'm trying to use Policies inside a Post Component, using Laravel. This is how I'm iterating through the posts in my page.
#foreach($posts as $post)
<x-post
:id="$post->id"
:title="$post->title"
:description="$post->description"
:userId="$post->user_id"
:img="$post->img"
:author="$post->user->name"/>
#endforeach
In the post.blade.php I'm trying to use a 'update' policy method to define which users can see the post:
#can('update', Auth::user(), /*What shoud I pass here?*/)
<a class="btn btn-success"href="{{route('posts.edit', $id)}}">
<i class="bi bi-pencil"></i>
</a>
#endcan
What should I pass as the second parameter of the policy? Normally, it would be a post variable. Since I'm already inside a post, I don't know to proceed.
You could check outside the component. Something like
#foreach ($posts as $post)
<x-post
:id="$post->id"
:title="$post->title"
:description="$post->description"
:userId="$post->user_id"
:img="$post->img"
:author="$post->user->name"
:canUpdate="Auth::user()->can('update', $post)"/>
#endforeach
#if ($canUpdate)
<a class="btn btn-success"href="{{ route('posts.edit', $id) }}">
<i class="bi bi-pencil"></i>
</a>
#endif

How to insert a variable into a Laravel Blade Template that is inside a HTML href tag for a web.root link

I am trying to creating a blog post with Laravel using views (blog.blade.php) inside HTML.
The code in my laravel web.php fetches the blog posts from my local mssql server looks as follow (and works):
Route::get('/blog/{id}', function($id){
$posts = DB::table('blog_posts')->get();
return view('blog', ['id'=>$id], ['posts'=>$posts]); });
In the laravel views dir home.blade.php my code works with hardcoded route: url('/blog/1')
The href link takes you to the full blog post
<h2>Blog posts:</h2>
#foreach ($posts as $post)
<p>{{ $post->title }} </p> <a href="{{ url('/blog/1') }}" >▲ Click here to view full post</a>
#endforeach
What I am trying to do is:
<p>{{ $post->title }} </p> <a href="{{ url('/blog/{{ $post->id }}') }}" >▲ Click here to view full post</a>
How do I get the $post->id that is the route (1, 2, 3 or 4) and comes from the sql data base saved to the blog row to work. I get the following error returned from my xampp php server when using {{ $post->id }} instead of hardcoding "1" .
D:\XAMPP Server\htdocs\cool-blog
ParseError
Unclosed '(' does not match '}' (View: D:\XAMPP Server\htdocs\cool-blog\resources\views\home.blade.php)
http://localhost:8000/
Pass second param to url() method
<p>{{ $post->title }} </p> <a href="{{ url('blog',$post->id) }}" >▲ Click here to view full post</a>
Ref:https://laravel.com/docs/8.x/helpers#method-url
Try this
<p>{{ $post->title }} </p> <a href="{{ url('/blog/'.$post->id.'') }}" >▲ Click here to view full post</a>

Multi Auth Laravel

I have just created multiple authentication laravel sucessfully. When i use these statement below, it has a little proplem.
#if(Auth::guard('student')->check())
<li><span style="color: white">Xin chào </span><a href="#" >{{Auth::guard('student')->student()->name}}</a></li>
#else
<li><a href="{{route('student.login')}}" >Login</a>
</li>
#endif
This Error is :
Method student does not exist.
Yes, i haven't yet created method student.
But if i change as {{Auth::guard('student')->user()->name}}.That's okay, it will display that name.
I don't know where it is i have to create student Method.
Inside the #if statement, you've already checked that a user with the guard 'student' is logged in, you don't need to check for that again, hence you can do something like this and it should work:
#if(Auth::guard('student')->check())
<li><span style="color: white">Xin chào </span><a href="#" >{{ Auth::user()->name }}</a></li>
#else
<li><a href="{{route('student.login')}}" >Login</a></li>
#endif

Included blade template repeating in each foreach loop iteration

I'm using Blade templating with Laravel and I'm trying to use a #foreach loop to display notifications. The problem is that if I have say 10 notifications, the first notification is repeated 10 times.
The code to output each notification:
#foreach ( Auth::user()->unreadNotifications as $notification )
{{ $notification->type->web_template }}
{{ $notification->id }}
#include($notification->type->web_template)
#endforeach
web_template will output a path to the template: notifications.web.user_alert
For each iteration of the loop the {{ $notification->type->web_template }} and {{ $notification->id }} will output what they're supposed to but #include($notification->type->web_template) will only output the first notification each time.
So the output will look like:
156 notification.web.new_message
You have a new message from Joe.
154 notification.web.user_alert
You have a new message from Joe.
145 notification.web.new_like
You have a new message from Joe.
I think it's some sort of cache issue maybe, but I couldn't find anyone with the same problem.
Any ideas?
UPDATE: Adding some code
Example notification view:
#extends('layouts.notification-wrapper')
#section('url', url('jobs/'.$notification->job_id.'#highlight'.$notification->bid_id))
#section('image', '/assets/img/no-photo.jpg')
#section('header', $notification->collector->firstname . ' ' . $notification->collector->secondname)
#section('description')
has placed a bid of €{{ number_format($notification->bid()->withTrashed()->first()->amount,0) }} on your job.
#stop
Notification wrapper:
<li #if(!$notification->read)
class="unread"
#endif>
<a href="#yield('url')" data-id="{{ $notification->id }}">
<div class="pull-left">
<img src="#yield('image')" class="img-circle" alt="user image">
</div>
<h4>
#yield('header')
<small><i class="fa fa-clock-o"></i> {{ $notification->created_at->diffForHumans()}}</small>
</h4>
<p> #yield('description')</p>
</a>
</li>
Answering my own question!
Found this: Laravel Blade Templates Section Repeated / cache error
Basically whatever way it works I need to overwrite my sections when looping and using #yield... I think. So I need to replace #stop with #overwrite in my views.

Categories