GithubHelp home page GithubHelp logo

glcordon / laravel-google-jobs Goto Github PK

View Code? Open in Web Editor NEW

This project forked from light-it-labs/laravel-google-jobs

0.0 0.0 0.0 50 KB

Google Job Posting integration for Laravel

License: MIT License

PHP 100.00%

laravel-google-jobs's Introduction

Laravel Google Job Posting Metadata Generator

Build Status

This package allows you to generate the required metadata for Google Jobs Announcements in a easy and Laravel way.

Installation

You can install this package via composer composer require lightit/laravel-google-jobs

The service provider will be auto discovered and then automatically added to your providers array.

Usage

Laravel Google Jobs provides two different ways of json generation:

  1. You can use the GJob facade available at: Lightit\LaravelGoogleJobs\Facades namespace

  2. You can use Laravel's dependency injection system. From your class constructor, inject the GJobContract. This will return a singleton instance of Lightit\LaravelGoogleJobs\GJob class.

use Lightit\LaravelGoogleJobs\Contracts\GJobContract;

class JobOfferController extends Controller
{
    /* @var GjobContract */
    private $gjob;

    public function __construct(GJobContract $gjob)
    {
        // $this->gjob is now a GJob class singleton instance
        $this->gjob = $gjob;
    }

}

Available API

Google Job Posting allows a specific set of fields for your jobs. Check: https://developers.google.com/search/docs/data-types/job-posting for more information.

Some of these fields are required, and others are optional. This package will help you through the process of generating and validating all this data properly, so you don't have to care about the formatting or the definitions of the JSON.

Methods

$this->gjob->fields(array $parameters): GJob

This method adds all array $parameters into your current instance and performs data validations. If one of the required parameters is missing from the array aLightit\LaravelGoogleJobs\Exceptions\FieldsValidationsException will be thrown specifying the missing required fields.


$this->gjob->withOptionals(array $parameters): GJob

As the name says, this method adds all array $parameters into your current instance, performing data validations. Only format validations are performed over these fields.


$this->gjob->generate(): string

Generates the proper JSON format and validates all the instance parameters.

Example

public function show(Request $request, $id)
{
    // Lets say we want to allow google to render our job offer

    // Cool! Is time to do some magic with this package, we are going to use the Facade for this example
     // All You have to do is create an array like this one.
      // We strongly recomend the use of a model accessor in order to avoid duplicated code and provide one single source of truth for your job offer array representation
    $jobArray = [
        'datePosted' => '...',
        'text' => '...',
        'hiringOrganization' => [
            '@type' => '...',
            'name' => '...',
            'sameAs' => '...',
            'logo' => '...'
        ],
        'jobLocation' => [
            '@type' => '...',
            'streetAddress'=> '...',
            'addressLocality'=> '...',
            'addressRegion'=> '...',
            'postalCode'=> '...',
            'addressCountry'=> '...'
        ],
        'title' => '...',
        'validThrough' => '...'
    ];

    // Add your array into the singleton instance
    GJob::fields($jobArray);

    return view('details');
}

Now, all you have to do is call to the generate() method directly on your view before you close the </body> tag

.
.
.
.

<p>I'm the best job offer ever!</p>

<script type="application/ld+json">
    {!! GJob::generate() !!}
</script>

</body>

And voila! A beautiful and fully compatible JSON is rendered for you.

About Lightit

Light-it is a digital product development studio with offices in the US, Uruguay and Paraguay.

License

This project and the Laravel framework are open-sourced software licensed under the MIT license.

laravel-google-jobs's People

Contributors

alanbrande avatar alt-w avatar glcordon avatar jp-light-it avatar juannitram avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.