jeudi 16 juin 2022

how to pass one data view and others view page in laravel

i have two pages file in my view first is my home blade then second is category blade and both of them using extends asidenav my problem is when im redirecting to category file it gives me a error Undefined variable: categories but in my home file when im redirecting it's working fine . i will describe my code.

in my controller HomeController i pass one data categories to home.blade.php

class HomeController extends Controller
{
    public function home()
    {
        $categories = Category::select('id','name')->get();

        return view('home', compact('categories'));
     }

     public function category(){
        return view('category');
     }
}

the output of my home.blade.php

@extends('asidenav')
@section('section')
<main>
    this is homepage
</main>
@endsection

you can see in my home blade there is a extends asidenav . inside of my asidenav extends the data categories i passed is inside of that asidenav to make a list of categories

the output of my extends asidenav where the data i pass categories

<ul>    
    @foreach($categories as $category)
        <li><a href=""><span></a>
    @endforeach
</ul>

when i click the ahref to redirect the category blade it gives the error undefined variable categories. but when im redirecting to home blade it's working the output of my category.blade.php

@extends('asidenav')
@section('section')
<main>
    this is category
</main>
@endsection

but when i tried this code in my category controller it's working fine the error of undefined variable categories not showing

   public function category()
        {
          $categories = Category::select('id','name')->get();

             return view('category', compact('categories'));
        }

my point here is i want to pass only single data categories in my home blade and others file blade like a props but i don't have a idea how to do that



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/SmvejFA
via IFTTT

mercredi 15 juin 2022

$request->route() returns null in laravel

I have this code:

class TotersProviderLoginController extends Controller
{

    private $oauthService;

    public function __construct(Request $request)
    {
        $provider = $request->route()->parameter('provider'); // error here
        if($provider == 'google')
            $this->oauthService = new GoogleOauthService();
        else
            throw new \Exception('Provider '.($provider ?? '').' not supported!');
    }

I have the following routes defined:

Route::get('login/toters/{provider}', 'Accounts\TotersProviderLoginController@redirectToProvider');
Route::get('login/toters/{provider}/redirect', 'Accounts\TotersProviderLoginController@handleProviderCallback');
Route::get('login/toters/{provider}/csrf', 'Accounts\TotersProviderLoginController@getCsrf');
Route::post('login/toters/{provider}/oauth', 'Accounts\TotersProviderLoginController@requestToken');
    

for some reason when I run

php artisan route:list --verbose

I get this error

In TotersProviderLoginController.php line 38:

  [Symfony\Component\Debug\Exception\FatalThrowableError]
  Call to a member function parameter() on null

so it's clear that $request->route() is returning null. Why is that? note: I'm using Laravel 5.8



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/xB4XD9p
via IFTTT

How to fix when I update composer on laravel

I trying to run my laravel 5 project on laravel 8. When I am trying to update my laravel composer. I am fetching this kind of problem.

Here the problem is



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/raD7kxU
via IFTTT

lundi 13 juin 2022

Laravel Undefined variable $

I'm getting this error:

Undefined variable $nilais

This is the code from my main.blade.php

<tbody>
            @foreach ($nilais as $nilai)
            <tr>
                <td class="text-center" scope="row"></td>
                <td></td>
                <td class="text-center"></td>
                <td class="text-center"></td>
                <td class="text-center"></td>
                <td class="text-center"></td>
                <td class="text-center"></td>
                <td class="text-center"></td>
                <td class="text-center">Lulus</td>
                <td class="text-center">
                    <button type="button" class="btn btn-warning"> Edit </button>
                    <button type="button" class="btn btn-danger"> Hapus </button>
                </td>
            </tr>
            @endforeach

my Controller

class MainController extends Controller
{
    public function index(){
        $nilais = Nilai::get();
        return view('main', compact('nilais'));
    }}

and this is the route

Route::get('/main', function () {
    return view('main');
});

I don't know what is wrong, please help.

I'm aware there are other questions like this, but I already tried the solutions, and nothings work.

Thank you so much.



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/57awQEu
via IFTTT

dimanche 12 juin 2022

How can i Redirect Laravel 7 Bulk Old URL to New URL ? 4000+ Old URLs to New

I want to redirect my Old URL to New URL

OLD URL : http://example.com/productsite-reviews

New URL : http://example.com/reviews/productsite.com

The problem is i have more than 4000+ URLS. Can we redirect the old URL to New URL without .htaccess file ?

this is my home route

Route::get('/', 'HomeController')->name( 'home' );

Is there any way to redirect these URL in bulk without writing htaccess code?



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/skl4GYN
via IFTTT

Laravel force http to https redirect but caused "too many redirects"

I have a Saas product which allows my end-user to bind their own domain to manage their products but I encountered an issue when I try to redirect those requests that is originally not requested by "http" to "https", the site will return "too many request redirection". Meanwhile, I do not want to configure port 443 into my nginx configuration as some of scenario, some of the request path might not need to neccessary to have "https". If I configured the force redirection in nginx which means all the request must served under "https" which might leads all of the request path is served via "https" but what I want to achieve is only some of the request path served under https only.

Below is the code that used to achieve the force redirection from http to https

 if (!$request->secure()) {
            return redirect()->secure($request->path());
        }


from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/MvoWaOc
via IFTTT

jeudi 9 juin 2022

Can not access a image file in controller using jquery in laravel

I am trying to catch all data to controller using jquery in laravel. Except image file, i caught all the data in controller and i tried lots of code but did not success. In the below i gave controller and view code of laravel.

View:

<form action="" method="post" enctype="multipart/form-data" id="forms">
@csrf
<div class="row">
    <div class="col-md-4"> 
        <label>Profile Picture</label>
        <input class="form-control" type="file" name="file" id="file">
    </div>
</div>
<div>
    <button type="submit" id="submit">Submit</button>
</div>
</form>
<script>
    $(function(){        
    $("#forms").on('submit', function(e){
        e.preventDefault();
        $.ajax({
            url:$(this).attr('action'),
            method:$(this).attr('method'),
            data:new FormData(this),
            processData:false,
            dataType:'json',
            contentType:false,
            success:function(data){
                console.log(data);
                
            }
        });
    });
});
</script>

Controller:

public function store(Request $request){
    return $request->all();  
}

and also i tried this code:

public function store(Request $request){
    return $request->file('file');  
}

i failed to catch the image file in my controller using javascript. please help if anyone can. Thank you



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/BtRMZg2
via IFTTT