Git Product home page Git Product logo

fmlaravel's Introduction

Installation

Install the Laravel framework

You will need the Composer PHP package manager to install Laravel and FMLaravel. You can install Composer from getcomposer.org

If you do not yet have the Laravel framework installed you will need to install Laravel by running the following command in terminal:

composer create-project laravel/laravel YourProjectName

Once Composer finishes the instalation you will need to give Laravel write access to the storage directory by running the following command in terminal:

chmod -R 777 storage

Instal FMLaravel

In your text editor open composer.json and add the following line to the "require" section of the file. This will tell Composer that your project requires FMLaravel.

"andrewmile/fm-laravel": "0.4.*"

Run the following command in terminal to install FMLaravel

composer update

Config

Back in your text editor open config/app.php and add the following line to the providers array:

'FMLaravel\Database\FileMakerServiceProvider',

In config/database.php change the default connection type to filemaker:

'default' => 'filemaker',

Still in config/database.php add the following to the connections array:

'filemaker' => [
	'driver'   => 'filemaker',
	'host'     => env('DB_HOST'),
	'database' => env('DB_DATABASE'),
	'username' => env('DB_USERNAME'),
	'password' => env('DB_PASSWORD'),
],

In your root directory create a new file named .env and add the following while including your database connection details:

DB_HOST=YourHost
DB_DATABASE=YourDatabase
DB_USERNAME=YourUsername
DB_PASSWORD=YourPassword

Note that if you are using version control you do not want the .env file to be a part of your repository so it is included in .gitignore by default.

Usage

Creating a Model

Laravel includes a command line tool called artisan that you can use for many helpful tasks, including generating files to avoid typing repetative boilerplate code.

You will want to have one model class per table that you are using in your project. Laravel uses a convention where it uses singular model names. To create a model for a tasks table run the following command in terminal:

php artisan make:model Task

The file that was generated for you is located at app/Task.php. This class extends Laravel's Eloquent Model class but we need it to extend the FMLaravel Model class instead. Delete the following line from the newly created Task.php file:

use Illuminate\Database\Eloquent\Model;

Then add the following line in its place:

use FMLaravel\Database\Model;

In your Model classes you will need to specify the layout that should be used when querying the tasks table in your FileMaker database. In order to do this add the following line inside the Task class:

protected $layoutName = 'YourTaskLayoutName';

By default Laravel will assume the primary key of your table is "id". If you have a different primary key you will need to add the following inside your class:

protected $primaryKey = 'YourTaskPrimaryKey';

Querying a table

In a file where you will query your FileMaker tasks data add the following at the top of the file:

use App\Task;

Now that you have imported your Task model you can run the following types of queries against your tasks table:

Find all records

$tasks = Task::all();

Find a record by its primary key

$task = Task::find(3); //will find the task record with a primary key of 3

Find a task that matches your find criteria. You can either pass in two parameters where the first is the field name and the second is the value to match on or you can pass in an array of field names and values.

//will find tasks where the task_name is 'Go to the store'
$tasks = Task::where('task_name', 'Go to the store')->get();

//will find tasks where task_name is 'Go to the store' and priority is 1
$tasks = Task::where([
	'task_name' => 'Go to the store',
	'priority'  => 1
])->get();

If you want to limit your query to the first record that matches your criteria you can use first() instead of get()

$tasks = Task::where('task_name', 'Go to the store')->first();

If you want to specify a number of records to limit your query by you can use the limit() method.

//will find the first 10 records that match the find criteria
$tasks = Task::where('task_name', 'Go to the store')->limit(10)->get();

You can also specify a number of records to skip with the skip() method.

//will find records that match the find criteria after skipping the first 10
$tasks = Task::where('task_name', 'Go to the store')->skip(10)->get();

These query methods can be chained so you can do something like the following:

//will find 10 records that match the find criteria after skipping the first 100
$tasks = Task::where('task_name', 'Go to the store')->skip(100)->limit(10)->get();

If you are using both skip() and limit() in the same query and would rather combine them into one method you can also use the following:

//will find 10 records that match the find criteria after skipping the first 100
$tasks = Task::where('task_name', 'Go to the store')->setRange(100, 10)->get();

By default the layout you set on the $layoutName property of your model will be used to query your data. However, if you need to specify a different layout for a specific query you may use the setLayout() method.

//will use the PastDue layout to perform the query
$tasks = Task::where('task_name', 'Go to the store')->setLayout('PastDue')->get();

To Dos

  • write documentation for authentication

fmlaravel's People

Contributors

andrewmile avatar

Stargazers

Alokik Pathak avatar  avatar Worajedt Sitthidumrong avatar Brian Hamm avatar Bajram Emini avatar Luis Gonzalez avatar Marcus Adolfsen avatar philip avatar  avatar  avatar Kirk Bater avatar Michael Wilson avatar org avatar

Watchers

James Cloos avatar Fabio Bosisio avatar Bob Minteer avatar Marcus Adolfsen avatar Sam R. avatar DynamicData avatar Jaywill Sands avatar Brian Hamm avatar

fmlaravel's Issues

Write/Save support?

Hi there!

Nice library, many thanks for providing it.

I'm just adding some features of my own regarding container fields (see here) but in particular I wanted to confirm with you that write operations are not supported at the moment, is that right? (not that I overlook anything..)

Laravel 5.3

is it possible it is not compatible with Laravel 5.3 yet? Problems when trying to install FMLaravel :)

thanks!

Incompatible with php 7

php 7 doesn't like the class Filemaker with a function named Filemaker. kolotic/filemaker-api is namespaced and php 7 ready. I suggest dumping your api in favor if it.

Error "Call to a member function prepare() on null" when creating new Filemaker model

When I try to create a new Filemaker model, I expect to create a new entry in Filemaker, but I receive an error saying "Call to a member function prepare() on null". It looks like the $pdo attribute in Illuminate\Database\Connection is not set.

The model (the bad attribute naming is made by client...)

<?php

//app/Models/Filemaker/Phonelog.php

namespace App\Models\Filemaker;

use FMLaravel\Database\Model;

class Phonelog extends Model
{
    protected $connection = 'filemaker';
    protected $layoutName = 'Basic';
    protected $primaryKey = 'Log Id';
    protected $fillable = [
        "Date",
        "Incoming|Outgoing",
        "Production ID",
        "Prod_Show_Combo",
        "From",
        "To",
        "Summary",
        "Result",
        "Topic",
        "Type",
    ];
}

The test

<?php

//tests/Learning/FilemakerDbTest.php

namespace Tests\Learning;

use App\Models\Filemaker\Phonelog;
use TestCase;

class FilemakerDbTest extends TestCase
{
    //DATABASE : fmsvr.rms.biz ?
    public function setUp()
    {
        parent::setUp();
        $this->model = new Phonelog;
    }

    public function testAll()
    {
        $logs = $this->model->all();

        $this->assertNotTrue($logs->isEmpty());
    }

    public function testEdit()
    {
        $form = [
            "Date" => "12/12/2012",
            "Incoming|Outgoing" => "Outgoing",
            "Production ID" => "p999",
            "Prod_Show_Combo" => "combo",
            "From" => "Joe Crisse",
            "To" => "Joe Crisse",
            "Summary" => "Sommaire",
            "Result" => "Result!",
            "Topic" => "Conclusion",
            "Type" => "type",
        ];

        $log = $this->model->create($form);

        $this->assertInstanceOf(Phonelog::class, $log);
    }
}

The PHPUnit log output. Please note that the first test works, so the connection to Filemaker server works too.

PHPUnit 4.8.24 by Sebastian Bergmann and contributors.

.E

Time: 4.06 seconds, Memory: 12.00Mb

There was 1 error:

1) Tests\Learning\FilemakerDbTest::testEdit
Error: Call to a member function prepare() on null

/home/vagrant/Code/rms-php-api/vendor/laravel/framework/src/Illuminate/Database/Connection.php:408
/home/vagrant/Code/rms-php-api/vendor/laravel/framework/src/Illuminate/Database/Connection.php:666
/home/vagrant/Code/rms-php-api/vendor/laravel/framework/src/Illuminate/Database/Connection.php:629
/home/vagrant/Code/rms-php-api/vendor/laravel/framework/src/Illuminate/Database/Connection.php:409
/home/vagrant/Code/rms-php-api/vendor/laravel/framework/src/Illuminate/Database/Connection.php:365
/home/vagrant/Code/rms-php-api/vendor/laravel/framework/src/Illuminate/Database/Query/Processors/Processor.php:32
/home/vagrant/Code/rms-php-api/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php:1970
/home/vagrant/Code/rms-php-api/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php:1337
/home/vagrant/Code/rms-php-api/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php:1621
/home/vagrant/Code/rms-php-api/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php:1590
/home/vagrant/Code/rms-php-api/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php:1481
/home/vagrant/Code/rms-php-api/tests/Learning/FilemakerDbTest.php:42

Escaping FM operators

Hi Andrew :)

Just wanted to point out, that by default in find queries, where statements respectively no FM operator escaping takes place. I think that's the default behaviour with laravel/eloquent so that might be neglected by a developer or two.. whereby I mean that as default behaviour this could be dangerous..

Silent FileMaker Errors and Empty Result sets

Hi Andrew

I've been working on a fork for a bit now and I would just like to note that I think it's suboptimal that FileMaker Errors (also in your testing branch) get silently discarded.

If there's an error I as a developer/system supporter would like to have a way of being informed about it. Also this makes it easier to diagnose initial installation problems (at first my connection failed due to some authentication error silently but I didnt get much of a helpful indication of that).

I would suggest introducing an exception to inform about FileMaker_Errors.

Also, when performing a find and no matching record is found, FileMaker returns an error (which I find somewhat silly behaviour, although might make sense in the original FM context). So if and when introducing exceptions I would also suggest excluding the "no matching record" FM error (has error code '401'). Possibly there are more similiar cases, but that's the obvious one I encountered.

Edit: Also in the context of verbosity, I would consider connecting the FM API logging mechanism by trying to feed it a PEAR_Logger conforming proxy to the laravel system / psr logger..

Error: Unsupported driver [filemaker] Laravel 5.2

Hello,

I'm working on laravel 5.2, and I have the Next Error: Unsupported driver [filemaker], I think that error is in config/app.php, arrays providers.

Which is the provider for Laravel 5.2?

Johan

Would the Auth Class interfere with Laravels Basic Auth setup?

Hi Andrew,
Thank you so much for making this connector. :)
Sorry im still finding my way through Laravel so it may be a silly question but will your Auth class work with having the Basic Auth that is boxed with L5 doing a simple login/signup?
I was thinking to have mysql to handle the user sign up/login and then after authenticated use the Filemaker DB to retrieve the data.
I have worked out how to have 2 DB's but i'm not getting the authenticated user using Auth::user()

what is your suggestion?

Error in Connection to filemaker

Hi,
I'm trying to connect Filemaker database, i tired all the steps given
https://github.com/andrewmile/FMLaravel
but it showing me the below error...

[Symfony\Component\Debug\Exception\FatalErrorException]
Class 'FileMaker' not found

I'm not getting from where this thing is happening....

Can any one suggest me regarding this issue.... Any Help

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.