.. _object_model: Object Model ============ The Object Model included with Laravel-Parse provides a beautiful, simple ActiveRecord implementation for working with Parse classes. Each class has a corresponding "Model" which is used to interact with that Parse class. Models allow you to query for data in your classes, as well as insert new records into parse. Defining Object Model --------------------- .. include:: ../how-to/generate-model.rst Object Model Conventions ------------------------ Parse Class Name ^^^^^^^^^^^^^^^^ By default Laravel-Parse expects that your Parse class will have the same name as your model has. But you can change that using the `parseClassName` attribute to determine the Parse class to use: .. code-block:: php protected static $parseClassName = "Customer"; Default Master Key Usage ^^^^^^^^^^^^^^^^^^^^^^^^ In Parse you may need sometimes permission to do heavy stuff, e.g. resetting the password for users or deleting rows from Parse, otherwise an exception will be thrown. This can be blocked if you determine the master key usage for your model, by adding the `defaultUseMasterKey` attribute to your model: .. code-block:: php protected static $defaultUseMasterKey = true; Create new Entry ---------------- You can use the `create` method to insert a new record in parse. The `create` method returns the saved model instance: .. literalinclude:: ../references/route-create.php :language: php :lines: 4-9 :dedent: 4 Retrieving Object Models ------------------------ Once you have created a model, you are ready to start retrieving data from your Parse class. Think of each Object Model as a powerful query builder allowing you to fluently query the Parse class associated with the model. For example: .. code-block:: php use App\Test; $flights = App\Test::all(); foreach ($tests as $test) { echo $test->string; } Retrieving Single Object Models / Aggregates --------------------------------------------- Of course, in addition to retrieving all of the records for a given table, you may also retrieve single records using `find` or `first`. Instead of returning a collection of models, these methods return a single model instance: .. code-block:: php // Retrieve a model by its objectId ... $test = App\Test::find("b9Hx6skhEX"); // Retrieve the first model matching the query constraints... $test = App\Test::where('number', 4)->first(); .. hint:: You can not use `find` method passing in an array with key values as you may known from Laravel. Laravel-Parse doesn't have this functionality and only will handle strings. Modify and Delete Object Models ------------------------------- Please refer to :ref:`quick-usage` for further information about how to modify and delete Object Models.