#Call controller from form whit tag a

13 messages · Page 1 of 1 (latest)

arctic vapor
#

Hello,
I am using version 9 of Laravel and I have created a controller to make use of an api with which I want to fill 3 fields, country, state and city; I have decided to see the option of being able to do it through a field within a <a> tag, but when calling the values in the route to make use of them with a foreach, the only thing I get is to bring the route of the controller instantiated in my method

Could you tell me if I'm doing something wrong?laravel

loud yacht
arctic vapor
#

Temporarily for the test of generating the <option> tags, it is static with countries, but my idea is to be able to send the contents of the country and city fields through parameters when appropriate @loud yacht

loud yacht
#

Read #rules

#

Please don’t post screenshots. Post actual code snippets.

loud yacht
#

I have no idea what you’re trying to do, as your code is bonkers. That’s not how you use <a> elements in HTML, and I have no idea why you’re making a route to call a route.

arctic vapor
#

I'll explain what I want to do and you'll tell me how

The Apicontroller controller has inside it an index function which, my idea, is to be executed by touching 3 inputs, country, state and city.

My idea, I don't know if it's wrong, is that the function is called when executing an action, from yesterday to today I've started working with blade components and to be exact with the controller component, with this it works for me, but I don't know how to send it within the parameters of the component the content of another input in such a way that if I call the component from the city input, for example, it takes as a parameter the content of the state input.

Shipping code update

Note:
The uses for the <a> tag and the route calling another route, have only been tests since I'm just starting Laravel. @loud yacht

#
                                    <div class="col-sm-4">
                                        <label for="documentplace" class="form-label">Lugar Expedición</label>
                                        <select class="form-select" name="documentplace" id="documentplace" aria-label="">
                                                <x-locations-api to="cities"/>
                                        </Select>
                                    </div>
#

Input:

#
<?php
namespace App\View\Components;
use Illuminate\Support\Facades\Http;
use Illuminate\View\Component;

class locationsApi extends Component
{
    public $country,$state,$to,$apires,$size,$headerlib,$lib, $clasification = ['country','state','city'],
    $url = "https://www.universal-tutorial.com/api/", 
    $token = "TokenText";


    /**
     * Create a new component instance.
     * @return void
     */

     public function __construct( $to='countries', $country = 'colombia', $state= 'Antioquia' , $default = '0' )
    {
        $this->to = $to;
        $this->country = $country;
        $this->state = $state;

        if ( $to == 'cities' ){
            $headerlib = $this->clasification[2];
            $lib = $to."/".$state;
        };
        if ( $to == 'states' ){
            $lib = $to."/".$country;
            $headerlib = $this->clasification[1];

        };
        if ( $to == 'countries'){
            $lib = $to;
            $headerlib = $this->clasification[0];
        }

        $this->lib = $lib;
        $this->headerlib = $headerlib;

        $getAuthToken = Http::withHeaders([
            "Accept" => "application/json",
            "api-token"=> $this->token,
            "user-email"=> "mail@mail.com"
        ])->get( $this->url.'getaccesstoken');

        $token = $getAuthToken->json('auth_token');

        $items = Http::withHeaders([
            "Authorization"=> "Bearer ". $token,
            "Accept"=> "application/json"
        ])->get( $this->url . $lib );

        // $result = $items->json();
        $this->apires = $items->json();
        
        if ( $default == 0 ) {
            return $this->apires;
        }
    }

    

    /**
     * Get the view / contents that represent the component.
     *
     * @return \Illuminate\Contracts\View\View|\Closure|string
     */
    public function render()
    {
        // dd($borncountry);
        return view('components.locations-api');
    }

}
#

View Component

#

@foreach ( $apires as $item )
    <option value="{{ $item[ $headerlib.'_name'] }}" >{{ $item[ $headerlib.'_name'] }}</option>
@endforeach